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.
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/nagiosStarting nagios: Running configuration check… done.Then, If we check the status of the service using the following command:
$ service nagios statusIt will report as Nagios is not running.
However when we check the processes using the following command:
$ ps aux | grep nagios.cfgWe 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.cfgnagios 1767 0.0 0.0 7272 628 ? S 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgSome 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.
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.
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.cfg2. 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 all3. Then we can execute the following commands:
For CentOS 5.x/6.x|RHEL 5.x/6.x:
$ make install-initFor CentOS 7.x|RHEL 7.x:
$ make install-init$ systemctl daemon-reload4. 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 COMMANDnagios 1735 0.0 0.0 7788 1596 ? Ss 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgnagios 1767 0.0 0.0 7272 628 ? S 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgNow 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 17355. 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 startFor CentOS 7.x|RHEL 7.x:
$ systemctl stop nagios.service$ systemctl start nagios.serviceWe can confirm that Nagios is running by using the following commands:
For CentOS 5.x/6.x|RHEL 5.x/6.x:
$ service nagios statusFor CentOS 7.x|RHEL 7.x:
$ systemctl status nagios.service
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-initOn Ubuntu 15.x/16.x/17.x:
$ sudo make install-init$ sudo systemctl daemon-reload3. 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 COMMANDnagios 1735 0.0 0.0 7788 1596 ? Ss 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgnagios 1767 0.0 0.0 7272 628 ? S 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgNow kill the two Nagios processes usually, the first one (1735) will automatically kill the child process (1767):
$ sudo kill 17354. Finally, we can start Service/Daemon
On Ubuntu 14.x
$ sudo service nagios startOn 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.serviceWe can confirm that Nagios is running by using the following commands:
For Ubuntu 14.x:
$ sudo service nagios statusFor Ubuntu 15.x/16.x/17.x:
$ sudo systemctl status nagios.service
All steps on Debian require to run as root. To become root simply run:
$ suAll 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.cfg2. After that, for installing the Service/Daemon we can use the following commands:
On Debian 7.x:
$ make install-initOn Debian 8.x/9.x:
$ make install-init$ systemctl daemon-reload3. 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 COMMANDnagios 1735 0.0 0.0 7788 1596 ? Ss 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgnagios 1767 0.0 0.0 7272 628 ? S 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgNow kill the two Nagios processes, usually the first one (1735) will automatically kill the child process (1767):
$ kill 17354. Finally, we can start Service/Daemon
On Debian 7.x
$ service nagios startOn 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.serviceWe can confirm that Nagios is running by using the following commands:
For Debian 7.x:
$ service nagios statusFor Debian 8.x/9.x:
$ systemctl status nagios.service
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.cfg2. 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-reload3. 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 COMMANDnagios 1735 0.0 0.0 7788 1596 ? Ss 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgnagios 1767 0.0 0.0 7272 628 ? S 13:39 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgNow kill the two Nagios processes, usually the first one (1735) will automatically kill the child process (1767):
$ kill 17354. 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.serviceWe can confirm that Nagios is running by using the following commands:
$ systemctl status nagios.service
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.cfg2. 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-init3. 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 COMMANDnagios 571 0.0 0.3 19408 3344 – Ss 2:12PM 0:00.06 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgnagios 646 0.0 0.3 19408 3356 – S 2:12PM 0:00.01 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfgNow kill the two Nagios processes usually, the first one (1735) will automatically kill the child process (1767):
$ kill 17354. Finally, we can start Service/Daemon
We can do this using the following command:
$ service nagios startWe can confirm that Nagios is running by using the following commands:
$ service nagios statusThis 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.cfgRunning 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 $NagiosCfgFileBecause 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