Wondering how to fix the ‘Nagios No lock file found in /var/run/nagios’ error in your Nagios? We can help you.
Often Nagios users report getting this error message when they restart the Nagios service.
Here at Bobcares, we get requests from our customers to fix similar issues as a part of Server Management Services.
Today let’s see how our Support Engineers fix this issue for our customers.
What causes ‘Nagios No lock file found in /var/run/nagios’ error
Before going into the solution for ‘Nagios: No lock file found’ let’s see the cause for this issue.
This is often seen when we start or restart the Nagios service.
We will see the following message:
Running configuration check… Stopping nagios: No lock file found in /var/run/nagios Starting nagios: Running configuration check… done.
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 fix ‘Nagios No lock file found in /var/run/nagios’
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.
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:
CentOS 5.x/6.x|RHEL 5.x/6.x
make install-init
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.
CentOS 5.x/6.x|RHEL 5.x/6.x
service nagios start
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:
CentOS 5.x/6.x|RHEL 5.x/6.x
service nagios status
CentOS 7.x|RHEL 7.x
systemctl status nagios.service
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:
Ubuntu 14.x
sudo make install-init
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
Ubuntu 14.x
sudo service nagios start
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:
Ubuntu 14.x
sudo service nagios status
Ubuntu 15.x/16.x/17.x
sudo systemctl status nagios.service
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:
Debian 7.x
make install-init
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
Debian 7.x
service nagios start
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:
Debian 7.x
service nagios status
Debian 8.x/9.x
systemctl status nagios.service
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
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 assistance? We can help you]