Various minor updates.

This commit is contained in:
Darren 'Tadgy' Austin 2022-08-24 00:42:32 +01:00
commit 74f9b63c0d

View file

@ -7,21 +7,21 @@
BWBAR_EXEC="/opt/bin/bwbar" BWBAR_EXEC="/opt/bin/bwbar"
DAEMON_EXEC="/usr/bin/daemon" 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 ))') 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)" RUNUSER="$(whoami)"
MONINTERFACE="eth0" MONINTERFACE="eth0"
# Allow configuration in /etc/default to override. # Allow configuration in /etc/default to override.
# Additional available variables: # Additional available variables:
# ENVIRONMENT=() # Extra environment passed to $EXEC. Must be an array. # DAEMON_ENVIRONMENT=() # Extra environment passed to $DAEMON_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.
# RUNUSER="" # Username to run the daemon as. Default: User who starts the script. # RUNUSER="" # Username to run the daemon as. Default: User who starts the script.
# MONINTERFACE="" # The interface to monitor for bandwidth usage. Default: eth0. # 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() { error() {
printf "%s: %s: %s\\n" "${BASH_SOURCE##*/}" "${BWBAR_EXEC##*/}" "$*" >&2 printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${BWBAR_EXEC##*/}" "$*" >&2
} }
checkconfigured() { checkconfigured() {
@ -37,10 +37,10 @@ checkconfigured() {
checkstatus() { checkstatus() {
local RET local RET
if su - "${RUNUSER:-$(whoami)}" -c "\"$DAEMON_EXEC\" --running -n \"${0##*rc.}\""; then 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 RET=0
else else
printf "%s: %s: %s\\n" "${BASH_SOURCE##*/}" "${BWBAR_EXEC##*/}" "running" printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${BWBAR_EXEC##*/}" "stopped"
RET=1 RET=1
fi fi
return $RET return $RET
@ -49,12 +49,12 @@ checkstatus() {
startdaemon() { startdaemon() {
checkconfigured || { checkconfigured || {
error "not started - pre-start checks failed" 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 if (( $? != 0 )); then
error "error starting daemon" error "error starting 'daemon'"
return 1 return 2
else else
return 0 return 0
fi fi
@ -85,7 +85,7 @@ case "$1" in
'start') 'start')
if checkstatus >/dev/null; then if checkstatus >/dev/null; then
error "already running" error "already running"
printf " %s\\n" "Try: $BASH_SOURCE status" >&2 printf " %s\\n" "Try: ${BASH_SOURCE[0]} status" >&2
RET=1 RET=1
else else
startdaemon startdaemon
@ -95,7 +95,7 @@ case "$1" in
'stop') 'stop')
if ! checkstatus >/dev/null; then if ! checkstatus >/dev/null; then
error "not running" error "not running"
printf " %s\\n" "Try: $BASH_SOURCE status" >&2 printf " %s\\n" "Try: ${BASH_SOURCE[0]} status" >&2
RET=1 RET=1
else else
stopdaemon stopdaemon
@ -103,20 +103,20 @@ case "$1" in
fi fi
;; ;;
'restart') 'restart')
if checkstatus >/dev/null; then checkstatus >/dev/null
stopdaemon && sleep "${RESTART_DELAY:-2}" && startdaemon (( $? != 3 )) && {
RET=$? stopdaemon >/dev/null 2>&1
else sleep "${RESTART_DELAY:-2}"
}
startdaemon startdaemon
RET=$? RET=$?
fi
;; ;;
'status') 'status')
checkstatus checkstatus
RET=$? 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 RET=1
;; ;;
esac esac