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}
  • Pingback: Install Nagios Core 4 on Ubuntu 12.04 LTS | GeekPeek.Net()

  • supto

    after running these command. when i try to start nagios, i get this :

    /etc/init.d/nagios: 53: /etc/init.d/nagios: /usr/usr/sbin/service: not found

    Hope there is a solution.

    • Mitch

      Hi Supto! I think you need to install start-stop-daemon and get service binary. Regards, Mitch

      • aleks

        Hello Mitch…
        i have the same problem… (/etc/init.d/nagios: 54: /etc/init.d/nagios: /usr/usr/usr/sbin/service: not found)..
        I’m not very expert! can you explain to me how to get it work?
        thanks in advance!
        and beautiful tutorials! 🙂

        • aleks

          Solved… i change manually this path /usr/usr/usr/sbin/service in /usr/sbin/service..
          i don’t know who generated this wrong path 🙂

          • Jonathan

            Anyone having this problems needs to open up /etc/init.d/nagios and edit

            check_config() {
            TMPFILE=$(mktemp /tmp/.configtest.XXXXXXXX)
            /usr/usr/usr/sbin/service nagios configtest > “$TMPFILE”
            WARN=`grep ^”Total Warnings:” “$TMPFILE” |awk -F: ‘{print $2}’ |sed s/’ ‘//g`
            ERR=`grep ^”Total Errors:” “$TMPFILE” |awk -F: ‘{print $2}’ |sed s/’ ‘//g`

            to read

            check_config() {
            TMPFILE=$(mktemp /tmp/.configtest.XXXXXXXX)
            /usr/sbin/service nagios configtest > “$TMPFILE”
            WARN=`grep ^”Total Warnings:” “$TMPFILE” |awk -F: ‘{print $2}’ |sed s/’ ‘//g`
            ERR=`grep ^”Total Errors:” “$TMPFILE” |awk -F: ‘{print $2}’ |sed s/’ ‘//g`

  • Pingback: Nagios on Ubuntu | rey()

  • c1c3ru

    hi! thanks for sharing your knowledge,but now in test is show:
    /usr/local/nagios/nagios-4.0.2# service nagios start
    * is not running
    $Starting nagios: /etc/init.d/nagios: 85: /etc/init.d/nagios: daemon: not found

    whos happen???

    • Mitch

      Hi c1c3ru, you should install daemon package: apt-get install daemon. Regards, Mitch

  • c1c3ru

    I did it but when I try, I can not get into the webinterface.

  • shegeeky

    IT took me plenty of modifications and when i got this, it worked like BINGO.
    Thank you

  • Hélio

    I tried to do everything to Nagios start, but don’t works.
    When I type service nagios start, shows to me the message below:
    * is not running
    I did the alterations and daemon was installed.

    • Mitch

      Hi Helio! I think you might have a problem with Nagios installation. Is Nagios installed properly? Regards, Mitch