Nagios Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!
Nagios is a Monitoring Tool and you are seeing this Nagios error Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd‘ for update! When you attempt to run a service command such as “Re-schedule the next check of this service”.
It is a common Nagios /usr/local/nagios/var/rw/ directory ownership problem on most Linux distributions. In this post we will explain how to fix this Nagios error Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update! in CentOS and Ubuntu Linux distributions.
See Also:
What this Nagios Error is About
So, if we dissect this error, what it is saying is that somehow we don’t have permissions to run the /usr/local/nagios/var/rw/nagios.cmd file. So, our first reaction is to check the permission on the file:
# cd /usr/local/nagios/var/rw/ # ls -l
total 0 prw-rw---- 1 nagios nagios 0 Mar 22 10:25 nagios.cmd
So, at this point, we are all tempted to just change the permissions on the cmd file, which will indeed resolve the problem until the nagios service is restarted again. Restarting will set the permissions to their original state again.
Fix for Ubuntu Server
We must change the group ownership of the /usr/local/nagios/var/rw/ directory. First stop the Nagios service and then change the group ownership and start Nagios service again:
# service nagios stop # sudo chown -R nagios:www-data /usr/local/nagios/var/rw/ # service nagios start
Now restart Apache web service.
# service apache2 restart
Fix for CentOS/RHEL Server
In CentOS we must to add apache user to nagios group and restart Nagios and Apache service:
# usermod -a -G nagios apache
Now restart nagios and apache web services.
For CentOS/RHEL 5/6 # service nagios restart # service httpd restart For CentOS/RHEL 7 # systemctl restart nagios # systemctl restart httpd
After restarting the services your issue has been resolved.
Enjoy it!