Recently we've been experiencing a lot of spam hitting our servers causing apache to topple over. To tackle this we've installed nagios to notify us/run some restart commands if the issue arises. Notifications function fine, but the restart scripts just wont kick in. We've taken the following steps:

  • Created our restart script located: /usr/share/nagios3/plugins/eventhandlers/restart_apache
  • Tested and ran via ./restart_apache CRITICAL SOFT 3 - can confirm the script works
  • Defined the command: /etc/nagios3/commands.cfg
define command{
        command_name restart-apache
        command_line /usr/local/nagios/libexec/eventhandlers/restart_apache $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
  • Applied the command to fire when current load notifications run: /etc/nagios3/conf.d/localhost_nagios2.cfg
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       localhost
        service_description             Current Load
        check_command                   check_load!5.0!4.0!3.0!10.0!6.0!4.0
        event_handler                   restart-apache
  • We've set the script to write to a text file when performing a restart, but nothing is happening (and apache stays down) - so something is not right. Any direction is much appreciated!Thanks

1 Answer 1


you should make sure that handlers are enabled and logging in your nagios.cfg


then try to tail your nagios logs (in my case /var/spool/nagios/nagios.log ) and wait for your event, you should see the handler being executed or failing

tail -f /var/spool/nagios/nagios.log | egrep HANDLER
  • Thanks for your response - I can confirm the script is now firing - however, we need to run sudo service apache2 stop - but this just wont fire from the script. Any idea? Jun 18, 2013 at 10:53
  • 1
    Make sure nagios is allowed to run that command via sudo, without a password and without requiring a TTY.
    – Keith
    Jun 18, 2013 at 15:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .