Various minor updates.
This commit is contained in:
parent
7fcce6c9d3
commit
74f9b63c0d
1 changed files with 24 additions and 24 deletions
|
|
@ -7,21 +7,21 @@
|
|||
BWBAR_EXEC="/opt/bin/bwbar"
|
||||
DAEMON_EXEC="/usr/bin/daemon"
|
||||
BWBAR_ARGS=('-f' '/run/bwbar.txt' '-p' '/run/bwbar.png' '-t' '5' '-x' '800' '-y' '8' '-b' '2' '${MONINTERFACE:-eth0}' '$(( ($(ip link show "${MONINTERFACE:-eth0}" | sed -nre "s/.*qlen (.*)$/\1/ p") / 100) * 90 ))')
|
||||
DAEMON_ARGS=('-N' '-n' "${0##*rc.}" '-r' '-a' '60' '-A' '5' '-L' '3600' '-M' '3' '-o daemon.debug' '--')
|
||||
DAEMON_ARGS=('-N' '-n' "${0##*rc.}" '-r' '-a' '60' '-A' '5' '-L' '3600' '-M' '3' '-l' 'daemon.err' '-b' 'daemon.debug' '-o' 'daemon.info' '--')
|
||||
RUNUSER="$(whoami)"
|
||||
MONINTERFACE="eth0"
|
||||
|
||||
# Allow configuration in /etc/default to override.
|
||||
# Additional available variables:
|
||||
# ENVIRONMENT=() # Extra environment passed to $EXEC. Must be an array.
|
||||
# SLAY_DELAY="" # Delay between the SIGTERM and SIGKILL on a 'stop'. Default: 2s.
|
||||
# RESTART_DELAY="" # Delay between stopping and starting on a 'restart'. Default: 2s.
|
||||
# DAEMON_ENVIRONMENT=() # Extra environment passed to $DAEMON_EXEC. Must be an array.
|
||||
# RUNUSER="" # Username to run the daemon as. Default: User who starts the script.
|
||||
# MONINTERFACE="" # The interface to monitor for bandwidth usage. Default: eth0.
|
||||
[[ -e "/etc/default/${0##*rc.}" ]] && source "/etc/default/${0##*rc.}"
|
||||
# SLAY_DELAY="" # Delay between the SIGTERM and SIGKILL on a 'stop'. Default: 2s.
|
||||
# RESTART_DELAY="" # Delay between stopping and starting on a 'restart'. Default: 2s.
|
||||
[[ -e "/etc/default/${0##*rc.}" ]] && { source "/etc/default/${0##*rc.}" || return 1 2>/dev/null || exit 1; }
|
||||
|
||||
error() {
|
||||
printf "%s: %s: %s\\n" "${BASH_SOURCE##*/}" "${BWBAR_EXEC##*/}" "$*" >&2
|
||||
printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${BWBAR_EXEC##*/}" "$*" >&2
|
||||
}
|
||||
|
||||
checkconfigured() {
|
||||
|
|
@ -37,10 +37,10 @@ checkconfigured() {
|
|||
checkstatus() {
|
||||
local RET
|
||||
if su - "${RUNUSER:-$(whoami)}" -c "\"$DAEMON_EXEC\" --running -n \"${0##*rc.}\""; then
|
||||
printf "%s: %s: %s\\n" "${BASH_SOURCE##*/}" "${BWBAR_EXEC##*/}" "running"
|
||||
printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${BWBAR_EXEC##*/}" "running"
|
||||
RET=0
|
||||
else
|
||||
printf "%s: %s: %s\\n" "${BASH_SOURCE##*/}" "${BWBAR_EXEC##*/}" "running"
|
||||
printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${BWBAR_EXEC##*/}" "stopped"
|
||||
RET=1
|
||||
fi
|
||||
return $RET
|
||||
|
|
@ -49,12 +49,12 @@ checkstatus() {
|
|||
startdaemon() {
|
||||
checkconfigured || {
|
||||
error "not started - pre-start checks failed"
|
||||
return 1
|
||||
return 2
|
||||
}
|
||||
su - "${RUNUSER:-$(whoami)}" -c "${ENVIRONMENT:+declare ${ENVIRONMENT[*]};} \"$DAEMON_EXEC\" ${DAEMON_ARGS[*]} \"$BWBAR_EXEC\" ${BWBAR_ARGS[*]}"
|
||||
su - "${RUNUSER:-$(whoami)}" -c "${DAEMON_ENVIRONMENT:+declare ${DAEMON_ENVIRONMENT[*]};} \"$DAEMON_EXEC\" ${DAEMON_ARGS[*]} \"$BWBAR_EXEC\" ${BWBAR_ARGS[*]}"
|
||||
if (( $? != 0 )); then
|
||||
error "error starting daemon"
|
||||
return 1
|
||||
error "error starting 'daemon'"
|
||||
return 2
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
|
|
@ -85,7 +85,7 @@ case "$1" in
|
|||
'start')
|
||||
if checkstatus >/dev/null; then
|
||||
error "already running"
|
||||
printf " %s\\n" "Try: $BASH_SOURCE status" >&2
|
||||
printf " %s\\n" "Try: ${BASH_SOURCE[0]} status" >&2
|
||||
RET=1
|
||||
else
|
||||
startdaemon
|
||||
|
|
@ -95,7 +95,7 @@ case "$1" in
|
|||
'stop')
|
||||
if ! checkstatus >/dev/null; then
|
||||
error "not running"
|
||||
printf " %s\\n" "Try: $BASH_SOURCE status" >&2
|
||||
printf " %s\\n" "Try: ${BASH_SOURCE[0]} status" >&2
|
||||
RET=1
|
||||
else
|
||||
stopdaemon
|
||||
|
|
@ -103,20 +103,20 @@ case "$1" in
|
|||
fi
|
||||
;;
|
||||
'restart')
|
||||
if checkstatus >/dev/null; then
|
||||
stopdaemon && sleep "${RESTART_DELAY:-2}" && startdaemon
|
||||
RET=$?
|
||||
else
|
||||
checkstatus >/dev/null
|
||||
(( $? != 3 )) && {
|
||||
stopdaemon >/dev/null 2>&1
|
||||
sleep "${RESTART_DELAY:-2}"
|
||||
}
|
||||
startdaemon
|
||||
RET=$?
|
||||
fi
|
||||
;;
|
||||
'status')
|
||||
checkstatus
|
||||
RET=$?
|
||||
;;
|
||||
*)
|
||||
printf "%s\\n" "Usage: $BASH_SOURCE <start|stop|restart|status>" >&2
|
||||
printf "%s\\n" "Usage: ${BASH_SOURCE[0]} <start|stop|restart|status>" >&2
|
||||
RET=1
|
||||
;;
|
||||
esac
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue