## Starting Nagios

IMPORTANT: Before you actually start Nagios, you'll have to make sure that you have configured it properly and verified the config data!

Methods For Starting Nagios

There are basically four different ways you can start Nagios:

1. Manually, as a foreground process (useful for initial testing and debugging)
2. Manually, as a background process
3. Manually, as a daemon
4. Automatically at system boot

Let's examine each method briefly...

Running Nagios Manually as a Foreground Process

If you enabled the debugging options when running the configure script (and recompiled Nagios), this would be your first choice for testing and debugging. Running Nagios as a foreground process at a shell prompt will allow you to more easily view what's going on in the monitoring and notification processes. To run Nagios as a foreground process for testing, invoke Nagios like this...

/usr/local/nagios/bin/nagios <main_config_file>

Note that you must specify the path/filename of the main configuration file (i.e. /usr/local/nagios/etc/nagios.cfg) on the command line.

To stop Nagios at any time, just press CTRL-C. If you've enabled the debugging options you'll probably want to redirect the output to a file for easier review later.

Running Nagios Manually as a Background Process

To run Nagios as a background process, invoke it with an ampersand as follows...

/usr/local/nagios/bin/nagios <main_config_file> &

Note that you must specify the path/filename of the main configuration file (i.e. /usr/local/nagios/etc/nagios.cfg) on the command line.

Running Nagios Manually as a Daemon

In order to run Nagios in daemon mode you must supply the -d switch on the command line as follows...

/usr/local/nagios/bin/nagios -d <main_config_file>

Note that you must specify the path/filename of the main configuration file (i.e. /usr/local/nagios/etc/nagios.cfg) on the command line.

Running Nagios Automatically at System Boot

When you have tested Nagios and are reasonably sure that it is not going to crash, you will probably want to have it start automatically at boot time. To do this (in Linux) you will have to create a startup script in your /etc/rc.d/init.d/ directory. You will also have to create a link to the script in the runlevel(s) that you wish to have Nagios to start in. I'll assume that you know what I'm talking about and are able to do this.

A sample init script (named daemon-init) is created in the base directory of the Nagios distribution when you run the configure script. You can install the sample script to your /etc/rc.d/init.d directory using the 'make install-init' command, as outlined in the installation instructions.

The sample init scripts are designed to work under Linux, so if you want to use them under FreeBSD, Solaris, etc. you may have to do a little hacking...

Stopping and Restarting Nagios

Directions on how to stop and restart Nagios can be found here.