diff --git a/daemons/daemon-util.in b/daemons/daemon-util.in index 5d7e89b03feff979df167b10045366b87e2edf1b..05e97b47ed72959c7d71774bb41e1a27104ecd8a 100755 --- a/daemons/daemon-util.in +++ b/daemons/daemon-util.in @@ -51,6 +51,29 @@ check_config() { return 0 } +# Checks the exit code of a daemon +check_exitcode() { + if [[ "$#" -lt 1 ]]; then + echo 'Missing exit code.' >&2 + return 1 + fi + + local rc="$1"; shift + + case "$rc" in + 0) ;; + 11) + echo "not master" + ;; + *) + echo "exit code $rc" + return 1 + ;; + esac + + return 0 +} + # Checks whether daemon is running check() { if [[ "$#" -lt 1 ]]; then diff --git a/doc/examples/ganeti.initd.in b/doc/examples/ganeti.initd.in index 5ad3a9ba265a947df9febeb64438e9bc2f53dda2..617d06df9c10a9b3455feee78c427144bd85068d 100644 --- a/doc/examples/ganeti.initd.in +++ b/doc/examples/ganeti.initd.in @@ -29,17 +29,13 @@ test -f "@PREFIX@/sbin/$NODED" || exit 0 check_exitcode() { RC=$1 - case $RC in - 0) - log_action_end_msg 0 - ;; - 11) - log_action_end_msg 0 "not master" - ;; - *) - log_action_end_msg 1 "exit code $RC" - ;; - esac + + if errmsg=$($DAEMON_UTIL check-exitcode $RC) + then + log_action_end_msg 0 "$errmsg" + else + log_action_end_msg 1 "$errmsg" + fi } start_action() {