The Problem
Unable to start Nagios Network Monitoring service after reboot.
-- var/log/messages ---- May 6 09:14:28 [hostname] nagios: Checking global event handlers... May 6 09:14:28 [hostname] nagios: Checking obsessive compulsive processor commands... May 6 09:14:28 [hostname] nagios: Checking misc settings... May 6 09:14:28 [hostname] nagios: Total Warnings: 0 May 6 09:14:28 [hostname] nagios: Total Errors: 0 May 6 09:14:28 [hostname] nagios: Things look okay - No serious problems were detected during the pre-flight check May 6 09:14:28 [hostname] nagios: Failed to obtain lock on file /var/run/nagios/nagios.pid: No such file or directory May 6 09:14:28 [hostname] nagios: Bailing out due to errors encountered while attempting to daemonize... (PID=9029) May 6 09:14:28 [hostname] systemd: nagios.service: control process exited, code=exited status=254 May 6 09:14:28 [hostname] systemd: Failed to start Nagios Network Monitoring. May 6 09:14:28 [hostname] systemd: Unit nagios.service entered failed state. May 6 09:14:28 [hostname] systemd: nagios.service failed.
$ less installed-rpms | grep nagios nagios-4.3.4-3.el7.x86_64 Mon Feb 18 14:30:00 2019 nagios-common-4.3.4-3.el7.x86_64 Mon Feb 18 14:29:59 2019
The Solution
In file “/etc/nagios/nagios.cfg“, the lock_file parameter was set to “/var/run/nagios/nagios.pid“. In CentOS/RHEL, it is not recommended to write into /var/run as /var/run is usually mounted as tmpfs, which is a partition mapped into your RAM. Obviously RAM gets cleared on reboot, so do all tmpfs file systems. Hence, the file “/var/run/nagios/nagios.pid” could not be found.
# cat /etc/nagios/nagios.cfg lock_file=/var/run/nagios/nagios.pid
In /etc/nagios/nagios.cfg, “lock_file” parameter should point to a directory where data is persistent across reboot. This is the lockfile that Nagios will use to store its PID number in when it is running in daemon mode. Change the lock_file parameter from “/var/run/nagios/nagios.pid” to “/nagios/nagios.pid”.
Save the changes and restart the “nagios” service.