diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-01-06 12:11:47 +0000 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-01-06 12:11:47 +0000 |
commit | 1cda480143fd0ab6b7d743cba470f2ac65e46194 (patch) | |
tree | dd2e3ec184a45c167f38e8d09a458e677ddedbd0 /debian | |
parent | 8cb21b4ce890b2af2718bd76cd662c2c38f3ebf8 (diff) |
Added test task to mauveserver init script
Diffstat (limited to 'debian')
-rw-r--r-- | debian/mauvealert-server.init | 134 |
1 files changed, 86 insertions, 48 deletions
diff --git a/debian/mauvealert-server.init b/debian/mauvealert-server.init index 592304f..71d287d 100644 --- a/debian/mauvealert-server.init +++ b/debian/mauvealert-server.init @@ -47,6 +47,7 @@ do_start() # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started + do_test || return 2 start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON --chuid $RUNASUSER --test > /dev/null \ || return 1 @@ -119,69 +120,106 @@ do_reopenlogs() { } +# +# Test the config file before execution +# +do_test() { + # + # Make sure we're root + # + [ "$USER" = "root" ] || return 1 + + # + # OK test. + # + su $RUNASUSER -s /bin/bash -c "$DAEMON -t $DAEMON_ARGS" 1>/dev/null 2>&1 || return 1 + return 0 +} + case "$1" in start) - [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" - do_start - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 || exit 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 || exit 1 ;; - esac - ;; + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 || exit 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 || exit 1 ;; + esac + ;; + stop) - [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" - do_stop - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 || exit 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 || exit 1 ;; - esac - ;; - status) - status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? - ;; - reload|force-reload) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 || exit 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 || exit 1 ;; + esac + ;; + + status) + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + # # If do_reload() is not implemented then leave this commented out # and leave 'force-reload' as an alias for 'restart'. # - log_daemon_msg "Reloading $DESC" "$NAME" - do_reload - log_end_msg $? - ;; + reload|force-reload) + log_daemon_msg "Reloading $DESC" "$NAME" + do_reload + log_end_msg $? + ;; + # # This is for use by logrotate, as the post-rotate method. # reopen-logs) - log_daemon_msg "Re-opening logs for $DESC" "$NAME" - do_reopenlogs - log_end_msg $? - ;; - restart) + log_daemon_msg "Re-opening logs for $DESC" "$NAME" + do_reopenlogs + log_end_msg $? + ;; + + # + # This is to test the configuration + # + test|config-test) + log_daemon_msg "Testing configuration for $DESC" "$NAME" + do_test + log_end_msg $? + ;; + # # If the "reload" option is implemented then remove the # 'force-reload' alias # - log_daemon_msg "Restarting $DESC" "$NAME" - do_stop - case "$?" in - 0|1) - do_start - case "$?" in - 0) log_end_msg 0 ;; - 1) log_end_msg 1 ;; # Old process is still running - *) log_end_msg 1 ;; # Failed to start - esac - ;; - *) - # Failed to stop - log_end_msg 1 - ;; - esac - ;; + restart) + log_daemon_msg "Restarting $DESC" "$NAME" + + do_test + if [ "$?" != "0" ] ; then + log_end_msg 1 # test failed + fi + + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) - #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 - echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 - exit 3 - ;; + #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|test}" >&2 + exit 3 + ;; esac |