Stopping And Restarting Nagios


Once you have Nagios up and running, you may need to stop the process or reload the configuration data "on the fly". This section describes how to do just that.

IMPORTANT: Before you restart Nagios, make sure that you have verified the configuration data using the -v command line switch, especially if you have made any changes to your config files. If Nagios encounters problem with one of the config files when it restarts, it will log an error and terminate.

Stopping And Restarting With The Init Script

If you have installed the sample init script to your /etc/rc.d/init.d directory you can stop and restart Nagios easily. If you haven't, skip this section and read how to do it manually below. I'll assume that you named the init script Nagios in the examples below...

Desired Action Command Description
Stop Nagios /etc/rc.d/init.d/nagios stop This kills the Nagios process
Restart Nagios /etc/rc.d/init.d/nagios restart This kills the current Nagios process and then starts Nagios up again
Reload Configuration Data /etc/rc.d/init.d/nagios reload Sends a SIGHUP to the Nagios process, causing it to flush its current configuration data, reread the configuration files, and start monitoring again

Stopping, restarting, and reloading Nagios are fairly simple with an init script and I would highly recommend you use one if at all possible.

Stopping and Restarting Nagios Manually

If you aren't using an init script to start Nagios, you'll have to do things manually. First you'll have to find the process ID that Nagios is running under and then you'll have to use the kill command to terminate the application or make it reload the configuration data by sending it the proper signal. Directions for doing this are outlined below...

Finding The Nagios Process ID

First off, you will need to know the process id that Nagios is running as. To do that, just type the following command at a shell prompt:

ps axu | grep nagios

The output should look something like this:

nagios  6808  0.0  0.7   840   352  p3 S    13:44   0:00 grep nagios
nagios 11149  0.2  1.0   868   488  ?  S   Feb 27   6:33 /usr/local/nagios/bin/nagios nagios.cfg
From the program output, you will notice that Nagios was started by user nagios and is running as process id 11149.

Manually Stopping Nagios

In order to stop Nagios, use the kill command as follows...

kill 11149

You should replace 11149 with the actual process id that Nagios is running as on your machine.

Manually Restarting Nagios

If you have modified the configuration data, you will want to restart Nagios and have it re-read the new configuration. If you have changed the source code and recompiled the main Nagios executable you should not use this method. Instead, stop Nagios by killing it (as outlined above) and restart it manually. Restarting Nagios using the method below does not actually reload Nagios - it just causes Nagios to flush its current configuration, re-read the new configuration, and start monitoring all over again. To restart Nagios, you need to send the SIGHUP signal to Nagios. Assuming that the process id for Nagios is 11149 (taken from the example above), use the following command:

kill -HUP 11149

Remember, you will need to replace 11149 with the actual process id that Nagios is running as on your machine.