Cosmetic changes.
This commit is contained in:
parent
1da710fccb
commit
eea9ff85a8
1 changed files with 27 additions and 23 deletions
|
@ -13,13 +13,13 @@ RUNUSER="tftp"
|
|||
# Additional available variables:
|
||||
# ENVIRONMENT=() # Extra environment passed to $EXEC. Must be an array.
|
||||
# EXTRA_ARGS=() # Extra arguments passed to $EXEC. Must be an array.
|
||||
# RUNUSER="" # The username to run the tftp daemon as. Default: tftp.
|
||||
# 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="" # The username to run the tftp daemon as. Default: tftp.
|
||||
[[ -e "/etc/default/${0##*rc.}" ]] && source "/etc/default/${0##*rc.}"
|
||||
[[ -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##*/}" "${EXEC##*/}" "$*" >&2
|
||||
printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${EXEC##*/}" "$*" >&2
|
||||
}
|
||||
|
||||
checkconfigured() {
|
||||
|
@ -34,17 +34,17 @@ checkconfigured() {
|
|||
checkstatus() {
|
||||
local RUNPIDS="$({ pgrep -f "$EXEC"; pgrep -F "$PIDFILE" 2>/dev/null; } | sort -u )"
|
||||
if [[ ! -z "$RUNPIDS" ]]; then
|
||||
printf "%s: %s: %s" "${BASH_SOURCE##*/}" "${EXEC##*/}" "running"
|
||||
printf "%s: %s: %s" "${BASH_SOURCE[0]##*/}" "${EXEC##*/}" "running"
|
||||
if [[ ! -z "$PIDFILE" ]]; then
|
||||
if [[ ! -e "$PIDFILE" ]]; then
|
||||
printf "%s" ", but .pid file does not exist"
|
||||
elif ! grep "\<$(< "$PIDFILE")\>" <<<"$RUNPIDS" >/dev/null 2>&1; then
|
||||
elif ! grep "\<$(<"$PIDFILE")\>" <<<"$RUNPIDS" >/dev/null 2>&1; then
|
||||
printf "%s" ", but .pid file is stale"
|
||||
fi
|
||||
fi
|
||||
printf "\\n"
|
||||
else
|
||||
printf "%s: %s: %s\\n" "${BASH_SOURCE##*/}" "${EXEC##*/}" "stopped"
|
||||
printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${EXEC##*/}" "stopped"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
|
@ -53,30 +53,34 @@ checkstatus() {
|
|||
startdaemon() {
|
||||
if [[ ! -e "$EXEC" ]]; then
|
||||
error "not found"
|
||||
return 1
|
||||
return 2
|
||||
elif [[ ! -x "$EXEC" ]]; then
|
||||
error "not executable"
|
||||
return 1
|
||||
return 2
|
||||
elif ! checkconfigured; then
|
||||
error "not started - pre-start checks failed"
|
||||
return 1
|
||||
return 2
|
||||
fi
|
||||
${ENVIRONMENT:+declare ${ENVIRONMENT[*]};} "$EXEC" ${ARGS[*]} ${EXTRA_ARGS[*]}
|
||||
if (( $? != 0 )); then
|
||||
error "error starting daemon"
|
||||
return 1
|
||||
return 2
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
stopdaemon() {
|
||||
[[ -e "$PIDFILE" ]] && kill -TERM "$(< "$PIDFILE")" >/dev/null 2>&1 || kill -TERM "$(pgrep -f "$EXEC" | tr $'\n' " ")" >/dev/null 2>&1
|
||||
kill -TERM "$(pgrep -f "$EXEC" | tr $'\n' " ")" >/dev/null 2>&1
|
||||
[[ -e "$PIDFILE" ]] && {
|
||||
sleep 0.5
|
||||
kill -TERM "$(<"$PIDFILE")" >/dev/null 2>&1
|
||||
}
|
||||
sleep "${SLAY_DELAY:-2}"
|
||||
if checkstatus >/dev/null; then
|
||||
checkstatus >/dev/null && {
|
||||
error "failed to stop gracefully - slaying"
|
||||
kill -KILL "$({ cat "$PIDFILE"; pgrep -f "$EXEC"; } 2>/dev/null | sort -u | tr $'\n' " ")" >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -84,7 +88,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
|
||||
|
@ -94,7 +98,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
|
||||
|
@ -102,20 +106,20 @@ case "$1" in
|
|||
fi
|
||||
;;
|
||||
'restart')
|
||||
if checkstatus >/dev/null; then
|
||||
stopdaemon && sleep "${RESTART_DELAY:-2}" && startdaemon
|
||||
RET=$?
|
||||
else
|
||||
startdaemon
|
||||
RET=$?
|
||||
fi
|
||||
checkstatus >/dev/null
|
||||
(( $? != 3 )) && {
|
||||
stopdaemon >/dev/null 2>&1
|
||||
sleep "${RESTART_DELAY:-2}"
|
||||
}
|
||||
startdaemon
|
||||
RET=$?
|
||||
;;
|
||||
'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