diff options
-rw-r--r-- | debian/control | 1 | ||||
-rw-r--r-- | debian/mauvealert-server.init | 134 | ||||
-rw-r--r-- | lib/mauve/processor.rb | 4 |
3 files changed, 89 insertions, 50 deletions
diff --git a/debian/control b/debian/control index ea29d70..fcaa9a5 100644 --- a/debian/control +++ b/debian/control @@ -36,6 +36,7 @@ Depends: mauvealert-common (>= 3.4.0), librmail-ruby1.8, libsanitize-ruby1.8 (>= 2.0.3), libsinatra-ruby1.8 (>= 1.0), + lsb-base (>= 3.2-14), ruby1.8 (>= 1.8.7), thin1.8 (>= 1.2.11) | thin (>= 1.2.11), libxmpp4r-ruby1.8, 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 diff --git a/lib/mauve/processor.rb b/lib/mauve/processor.rb index c8a1dfb..0e59778 100644 --- a/lib/mauve/processor.rb +++ b/lib/mauve/processor.rb @@ -100,7 +100,7 @@ module Mauve # # Uh-oh. Nil data? That's craaaazy # - break if data.nil? + next if data.nil? # logger.debug("Got #{data.inspect} from #{client.inspect}") @@ -119,7 +119,7 @@ module Mauve next end - logger.debug "Update #{update.transmission_id} sent at #{update.transmission_time} from "+ + logger.debug "Update #{update.transmission_id} sent at #{update.transmission_time} received at #{received_at.to_i} from "+ "'#{update.source}'@#{ip_source} alerts #{update.alert.length}" Alert.receive_update(update, received_at, ip_source) |