Share, , Google Plus, Pinterest,

Print

Posted in:

Ubuntu Nagios 4 Init Script Fix

If you ever tried installing Nagios IT Infrastructure Monitoring Tool on Ubuntu, you probably already know that Ubuntu Nagios 4 init script is not working by default and needs to be fixed to make it work. In this post I am providing information on how I made Ubuntu Nagios 4 init script to work on Ubuntu Server 12.04 LTS. Read this post to fix Ubuntu Nagios 4 init script.

Ubuntu Nagios 4 Init Script Hack
Ubuntu Nagios 4 Init Script Hack

Let’s Fix Ubuntu Nagios 4 Init Script!

If you try to start Nagios 4 on Ubuntu after finishing Nagios installation you will get the following error:

geekpeeknet@foo1:~$ sudo /etc/init.d/nagios start
/etc/init.d/nagios: 20: .: Can't open /etc/rc.d/init.d/functions

 

There is a problem with Nagios 4 init script on Ubuntu. We have to edit init script and change a few lines. I could not get it to work with none of the hacks i found on the internet so i created my own by first running “start-stop-daemon” and then killing the daemon PID since a defunct Nagios process seems to hang. If you do not like this hack do not use it – but it works!

Copy and paste this to your console it will fix /etc/init.d/nagios file:

sudo sed -i "s/^. /etc/rc.d/init.d/functions$/. /lib/lsb/init-functions/g" /etc/init.d/nagios
sudo sed -i "s/status /status_of_proc /g" /etc/init.d/nagios
sudo sed -i "s/daemon --user=$user $exec -ud $config/daemon --user=$user -- $exec -d $config/g" /etc/init.d/nagios
sudo sed -i "s//var/lock/subsys/$prog//var/lock/$prog/g" /etc/init.d/nagios
sudo sed -i "s//sbin/service nagios configtest//usr/sbin/service nagios configtest/g" /etc/init.d/nagios
sudo sed -i "s/" == "/" = "/g" /etc/init.d/nagios
sudo sed -i "s/##killproc -p ${pidfile} -d 10/killproc -p ${pidfile}/g" /etc/init.d/nagios
sudo sed -i "s/runuser/su/g" /etc/init.d/nagios
sudo sed -i "s/use_precached_objects="false"/&ndaemonpid=$(pidof daemon)/" /etc/init.d/nagios
sudo sed -i "s/killproc -p ${pidfile} -d 10 $exec//sbin/start-stop-daemon --user=$user $exec --stop/g" /etc/init.d/nagios
sudo sed -i "s//sbin/start-stop-daemon --user=$user $exec --stop/&ntkill -9 $daemonpid/" /etc/init.d/nagios

 

Now we can try to start our Nagios service:

root@foo1:/home/geekpeeknet# sudo service nagios start
 *  is not running
$Starting nagios: daemon: debug: config()
daemon: debug: config_load(configfile = /etc/daemon.conf)
daemon: debug: config_load(configfile = /home/nagios/.daemonrc)
daemon: debug: config_process(target = *)
daemon: debug: handle_user_option(spec = nagios)
daemon: debug: sanity_check()

..and it works!

There are also other parameters you can use with init script and they all work:

root@foo1:/home/geekpeeknet# sudo service nagios
$Usage: /etc/init.d/nagios {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}