I ran an update on a CentOS server running Nagios, after the update, Nagios failed to start.
The error in the logs was:
Failed to obtain lock on file /var/run/nagios.pid: Permission denied
So, I checked and there was no pid file for Nagios in /var/run. I created one and gave it the following permissions:
-rwxr--r-- 1 nagios nagios 6 May 31 11:58 nagios.pid
Nagios then started and seems to be running normally.
The only problem is, it refuses to stop now, so I can't re-start it to add new servers and services to be monitored!
When I issue the command "service nagios stop", I get [FAILED], but nothing at all gets outputted to the log, and the service remains up.
Any ideas on how I can get the service to stop now?
I'm running the RPM version which was installed via yum from the RPMForge repositories. The server is CenotOS 5.5.
If you don't want to change the permissions on the /var/run folder itself, you can configure nagios to store the lock file anywhere on the system by adding the line below to your nagios.cfg file. As long as you point the lock_file option to a directory that nagios has access to create, modify and delete files then you should be good to go.
You could even store the lock file within your nagios installation directory by creating a a directory like: /usr/lib/nagios/var
First, find out what the
pid
ofnagios
process is:Then you can use this command to restart the service:
and this to stop:
To stop nagios automatically , you should have its
pid
in/var/run/nagios.pid
. Check it.As Bart B said above, do not chmod 777 any directory on a production system, ever, unless there is a really good reason for it and you know what you are doing. This was a quick fix, but this is not the solution.
The correct solution to this problem, at least for me, was to update the nagios.cfg Nagios configuration file (mine is /etc/nagios/nagios.cfg), and to change this line:
to this:
The lock file is set to /var/nagios/nagios.pid in the /etc/init.d/nagios service configuration file, but is apparently overridden by the above value in nagios.cfg
Then you may restart the Nagios service/daemon:
That should do it.
On Centos/RedHat 7 you are not supposed to write directly to the /var/run directory, but you got a subdirectory /var/run/nagios. Check that the lock_file option points there instead like this:
If the Nagios server has a problem with start/stop on CentOS 6.x I use this command:
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
It works on my Nagios server.
How about:
/etc/init.d/nagios stop
I got the same behavior updating to centos 5.5 For me it goes if I change the permission of /var/run with 777:
chmod 777 /var/run
I know it's not the best hack, but i didn't have much time to diagnose what's the problem.