×


Nagios No lock file found - Fix this error now

Are you trying to resolve the error , Nagios: No lock file found ?

This guide is for you.

Sometimes Nagios users report getting this error message when they restart the Nagios service.
This usually happens when a script is running and being used as the startup script when trying to restart Nagios.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to resolve related Nagios errors.

What triggers the error, Nagios: No lock file found ?

Basically, 'Nagios: No lock file found' error is sometimes experienced when we start or restart the Nagios service.
When this happens, you will see an error message such as this:

Running configuration check… Stopping nagios: No lock file found in /var/run/nagios
Starting nagios: Running configuration check… done.

Then, If we check the status of the service using the following command:

$ service nagios status

It will report as Nagios is not running.

However when we check the processes using the following command:

$ ps aux | grep nagios.cfg

We can see that it is running:

nagios 1735 0.0 0.0 7788 1592 ? Ss 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 1767 0.0 0.0 7272 628 ? S 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Some changes were introduced in Nagios Core 4.3.3 related to nagios.lock file.

These changes require an update to nagios.cfg file.
Otherwise, we will most likely experience this error.

How to resolve the error, 'Nagios: No lock file found' ?

The fix is to update the nagios.cfg file to point to /var/run/nagios.lock.
We can do this with the following commands.
After that, we need to install the latest service from the source code.
Also, we need to kill the existing Nagios processes and start the Nagios service.

On CentOS|RHEL:

1. For updating nagios.cfg we can use the following command:

$ sed -i ‘s/^lock_file=.*/lock_file=\/var\/run\/nagios.lock/g’ /usr/local/nagios/etc/nagios.cfg

2. After that, for installing the Service/Daemon we can use the following commands:

$ cd /tmp
$ wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.5.tar.gz
$ tar xzf nagioscore.tar.gz
$ cd /tmp/nagioscore-nagios-4.4.5/
$ ./configure
$ make all

3. Then we can execute the following commands:
For CentOS 5.x/6.x|RHEL 5.x/6.x:

$ make install-init

For CentOS 7.x|RHEL 7.x:

$ make install-init
$ systemctl daemon-reload

4. Then we will kill existing Nagios processes using the following commands:

$ ps aux | egrep “PID|nagios.cfg”

The following output can be seen:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
nagios 1735 0.0 0.0 7788 1596 ? Ss 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 1767 0.0 0.0 7272 628 ? S 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Now kill the two Nagios processes, usually, the first one (1735) will automatically kill the child process (1767).
We can do this with the following command:

$ kill 1735

5. Finally, we can start Service/Daemon
The following commands will start Nagios Core.

For CentOS 5.x/6.x|RHEL 5.x/6.x:

$ service nagios start

For CentOS 7.x|RHEL 7.x:

$ systemctl stop nagios.service
$ systemctl start nagios.service

We can confirm that Nagios is running by using the following commands:
For CentOS 5.x/6.x|RHEL 5.x/6.x:

$ service nagios status

For CentOS 7.x|RHEL 7.x:

$ systemctl status nagios.service

On Ubuntu

1. For updating nagios.cfg we can use the following command:

$sudo sh -c “sed -i ‘s/^lock_file=.*/lock_file=\/var\/run\/nagios.lock/g’ /usr/local/nagios/etc/nagios.cfg”

2. After that, for installing the Service/Daemon we can use the following commands:
On Ubuntu 14.x:

$ sudo make install-init

On Ubuntu 15.x/16.x/17.x:

$ sudo make install-init
$ sudo systemctl daemon-reload

3. Then we will kill existing Nagios processes using the following commands:

$ ps aux | egrep “PID|nagios.cfg”

The output will be something like this:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
nagios 1735 0.0 0.0 7788 1596 ? Ss 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 1767 0.0 0.0 7272 628 ? S 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Now kill the two Nagios processes usually, the first one (1735) will automatically kill the child process (1767):

$ sudo kill 1735

4. Finally, we can start Service/Daemon


On Ubuntu 14.x

$ sudo service nagios start

On Ubuntu 15.x/16.x/17.x:
A stop is required first, even though the processes are not running. This appears to be a systemd feature.

$ sudo systemctl stop nagios.service
$ sudo systemctl start nagios.service

We can confirm that Nagios is running by using the following commands:
For Ubuntu 14.x:

$ sudo service nagios status

For Ubuntu 15.x/16.x/17.x:

$ sudo systemctl status nagios.service

For Debian:

All steps on Debian require to run as root. To become root simply run:

$ su

All commands from this point onwards will be as root.
1. For updating nagios.cfg we can use the following command:

$ sed -i ‘s/^lock_file=.*/lock_file=\/var\/run\/nagios.lock/g’ /usr/local/nagios/etc/nagios.cfg

2. After that, for installing the Service/Daemon we can use the following commands:
On Debian 7.x:

$ make install-init

On Debian 8.x/9.x:

$ make install-init
$ systemctl daemon-reload

3. Then we will kill existing Nagios processes using the following commands:

$ ps aux | egrep “PID|nagios.cfg”

We can see the following output:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
nagios 1735 0.0 0.0 7788 1596 ? Ss 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 1767 0.0 0.0 7272 628 ? S 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Now kill the two Nagios processes, usually the first one (1735) will automatically kill the child process (1767):

$ kill 1735

4. Finally, we can start Service/Daemon
On Debian 7.x

$ service nagios start

On Debian 8.x/9.x
A stop is required first, even though the processes are not running. This appears to be a systemd feature.

$ systemctl stop nagios.service
$ systemctl start nagios.service

We can confirm that Nagios is running by using the following commands:
For Debian 7.x:

$ service nagios status

For Debian 8.x/9.x:

$ systemctl status nagios.service

On Fedora

1. For updating nagios.cfg we can use the following command:

$ sed -i ‘s/^lock_file=.*/lock_file=\/var\/run\/nagios.lock/g’ /usr/local/nagios/etc/nagios.cfg

2. After that, for installing the Service/Daemon we can use the following commands:
Once the updated service/daemon is installed, please execute the following commands:

$ make install-init
$ systemctl daemon-reload

3. Then we will kill existing Nagios processes using the following commands:
We will execute the following command:

$ ps aux | egrep “PID|nagios.cfg”

We can see the following output:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
nagios 1735 0.0 0.0 7788 1596 ? Ss 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 1767 0.0 0.0 7272 628 ? S 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Now kill the two Nagios processes, usually the first one (1735) will automatically kill the child process (1767):

$ kill 1735

4. Finally, we can start Service/Daemon
A stop is required first, even though the processes are not running. This appears to be a systemd feature.

$ systemctl stop nagios.service
$ systemctl start nagios.service

We can confirm that Nagios is running by using the following commands:

$ systemctl status nagios.service

On FreeBSD

1. For updating nagios.cfg we can use the following command:

$ sed -i ” ‘s/^lock_file=.*/lock_file=\/var\/run\/nagios.lock/g’ /usr/local/nagios/etc/nagios.cfg

2. After that, for installing the Service/Daemon we can use the following commands:
Once the updated service/daemon is installed, please execute the following commands:

$ gmake install-init

3. Then we will kill existing Nagios processes using the following commands:
We can execute the following command:

$ ps aux | egrep “PID|nagios.cfg”

We can see the following output:

USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
nagios 571 0.0 0.3 19408 3344 – Ss 2:12PM 0:00.06 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 646 0.0 0.3 19408 3356 – S 2:12PM 0:00.01 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Now kill the two Nagios processes usually, the first one (1735) will automatically kill the child process (1767):

$ kill 1735

4. Finally, we can start Service/Daemon
We can do this using the following command:

$ service nagios start

We can confirm that Nagios is running by using the following commands:

$ service nagios status


[Need urgent assistance in fixing Nagios errors? We can help you. ]


Conclusion

This article covers different methods to resolve the error, Nagios: No lock file found.  Basically, "No lock file found in /usr/local/nagios/var/nagios.lock" means that the service isn't running.

To fix this Nagios error:
Execute the command:

$ /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Running the command above simply starts the nagios daemon and points it to a specific config file.
The advantage to running this command manually over systemd is that when you run "service nagios start" this typically calls the /etc/rc.d/init.d/nagios script which contains a line with parametrized environment variables:

$NagiosBin -d $NagiosCfgFile

Because every system is different, not specifying either the bin nor config directories could lead to nagios breaking (stopping) when it tries to start using the default installation directory paths