Ubuntu 12.04 Nagios 4.0.2 issue w/ /etc/init.d/nagios

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
5mall5nail5
Posts: 7
Joined: Mon Feb 24, 2014 5:19 pm

Ubuntu 12.04 Nagios 4.0.2 issue w/ /etc/init.d/nagios

Post by 5mall5nail5 »

Hi all, I followed this guide:

http://wellsie.net/p/248/

He gets down to saying that

[root]$ service nagios start
/etc/init.d/nagios: 20: .: Can't open /etc/rc.d/init.d/functions

there's an issue ^^^

Ok, so I paste the text (well not really because I can only SSH into the server via putty, but I nano a file and then cp/mv/etc it to /etc/init.d/ and I get:

Last login: Mon Feb 24 15:56:40 2014 from <hidden>
sroot@<hidden>:~# service nagios restart
: not found/nagios: 11: /etc/init.d/nagios:
: not found/nagios: 16: /etc/init.d/nagios:
: not found/nagios: 18: /etc/init.d/nagios:
: not found/nagios: 33: /etc/init.d/nagios:

What gives?
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Ubuntu 12.04 Nagios 4.0.2 issue w/ /etc/init.d/nagios

Post by abrist »

There are issues with the init script and ubuntu. A bug has been filed. See:
http://tracker.nagios.org/view.php?id=491
A user posted a workaround on his/her github:
https://github.com/curvedental/ubuntu_nagios4_init
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
mkot
Posts: 68
Joined: Tue Feb 25, 2014 1:47 am
Location: Poland

Re: Ubuntu 12.04 Nagios 4.0.2 issue w/ /etc/init.d/nagios

Post by mkot »

I had the same error, I did:

~20 line: # . /etc/rc.d/init.d/functions
. /lib/lsb/init-functions
and it helped me but after this I also had 2 more errors and 1 issue:

1.

~37 line:
We need to find lockfile=/var/lock/subsys/$progasfasf and change it to lockfile=/var/lock/$progasfasf otherwise we will get errors that there is no /var/lock/subsys/nagios directory (it had to be /var/lock/nagios directory).


2.
„/etc/init.d/nagios: 52: /etc/init/d/nagios: /sbin/service: not found”

~52line (check_config(){): /sbin/service nagios configtest… change to /usr/sbin/service nagios configtest…

3.
„/etc/init.d/nagios: 147: /etc/init/d/nagios: runuser: not found”

~147 line: $nice runuser –s /bin/bash… change to $nice su –s /bin/bash…
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Ubuntu 12.04 Nagios 4.0.2 issue w/ /etc/init.d/nagios

Post by tmcdonald »

@mkot: Thank you for the answer.

@5mall5nail5: Can you please try the second link abrist posted? Failing that we can look at mkot's solution.
Former Nagios employee
mkot
Posts: 68
Joined: Tue Feb 25, 2014 1:47 am
Location: Poland

Re: Ubuntu 12.04 Nagios 4.0.2 issue w/ /etc/init.d/nagios

Post by mkot »

Oh, I forgot to say, that 'my' method is good for

Code: Select all

/etc/init.d/nagios: 20: .: Can't open /etc/rc.d/init.d/functions
error. For

Code: Select all

sroot@<hidden>:~# service nagios restart
: not found/nagios: 11: /etc/init.d/nagios:
isn't - acctually I've got similar problem with Nagios, but I think I'll open new thread for this (or I can write it here if you want).
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Ubuntu 12.04 Nagios 4.0.2 issue w/ /etc/init.d/nagios

Post by abrist »

Scott fixed u bunch of stuff in the init script, should be in a future release:
http://sourceforge.net/p/nagios/nagiosc ... on-init.in
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
mkot
Posts: 68
Joined: Tue Feb 25, 2014 1:47 am
Location: Poland

Re: Ubuntu 12.04 Nagios 4.0.2 issue w/ /etc/init.d/nagios

Post by mkot »

I hope it'll solve this issue:

Code: Select all

1.
root@nagios:~# service nagios stop
status: Unknown job: nagios

root@nagios:~# /etc/init.d/nagios stop
status: Unknown job: nagios

2.
root@nagios:~# service nagios stop
$Stopping nagios: Illegal option -d
/sbin/start-stop-daemon: signal value must be numeric or name of signal (KILL, INT, ...)
Try '/sbin/start-stop-saemon --help' for more information.

$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()

root@nagios:~# /etc/init.d/nagios restart
$Stopping nagios: Illegal option -d
/sbin/start-stop-daemon: signal value must be numeric or name of signal (KILL, INT, ...)
Try '/sbin/start-stop-saemon --help' for more information.

$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()
So in the end Nagios Service isn't stopping when I use stop.
When I use restart old Nagios Service isn't killed and new instance is starting work - I've got dwo instances of Nagios' processes. If I want 'fix' it I need restart whole Nagios's Server machine. I can restart Nagios' process only wrom GUI -> Process Info -> Restart the Nagios process.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Ubuntu 12.04 Nagios 4.0.2 issue w/ /etc/init.d/nagios

Post by abrist »

Which script are you using? The one from core(github), the original, or the one from the community (gihub)?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
mkot
Posts: 68
Joined: Tue Feb 25, 2014 1:47 am
Location: Poland

Re: Ubuntu 12.04 Nagios 4.0.2 issue w/ /etc/init.d/nagios

Post by mkot »

Hi, I'm using default script from Nagios 4.0.2 (a few days ago I updated it to v4.0.3).
Below is my script. I added some modifications which I mentioned eariel in this thread.

Code: Select all

#!/bin/sh

# Nagios	Startup script for the Nagios monitoring daemon
#
# chkconfig:	- 85 15
# description:	Nagios is a service monitoring system
# processname: nagios
# config: /etc/nagios/nagios.cfg
# pidfile: /var/nagios/nagios.pid
#
### BEGIN INIT INFO
# Provides:		nagios
# Required-Start:	$local_fs $syslog $network
# Required-Stop:	$local_fs $syslog $network
# Short-Description:	start and stop Nagios monitoring server
# Description:		Nagios is is a service monitoring system
### END INIT INFO

# Source function library.
#. /etc/rc.d/init.d/functions
. /lib/lsb/init-functions

prefix="/usr/local/nagios"
exec_prefix="${prefix}"
exec="${exec_prefix}/bin/nagios"
prog="nagios"
config="${prefix}/etc/nagios.cfg"
pidfile="${prefix}/var/nagios.lock"
user="nagios"
group="nagios"
checkconfig="true"
ramdiskdir="/var/nagios/ramcache"
use_precached_objects="false"

test -e /etc/sysconfig/$prog && . /etc/sysconfig/$prog

#lockfile=/var/lock/subsys/$prog
lockfile=/var/lock/$prog
USE_RAMDISK=${USE_RAMDISK:-0}

if test "$USE_RAMDISK" -ne 0 && test "$RAMDISK_SIZE"X != "X"; then
	ramdisk=`mount |grep "$ramdiskdir type tmpfs"`
	if [ "$ramdisk"X == "X" ]; then
		mkdir -p -m 0755 $ramdiskdir
		mount -t tmpfs -o size=${RAMDISK_SIZE}m tmpfs $ramdiskdir
		mkdir -p -m 0755 $ramdiskdir/checkresults
		chown -R $user:$group $ramdiskdir
	fi
fi

check_config() {
	TMPFILE=$(mktemp /tmp/.configtest.XXXXXXXX)
	#/sbin/service nagios configtest > "$TMPFILE"
	/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`

	if test "$WARN" = "0" && test "${ERR}" = "0"; then
		echo "OK - Configuration check verified" > /var/run/nagios.configtest
		chmod 0644 /var/run/nagios.configtest
		/bin/rm "$TMPFILE"
    	return 0
	else
		# We'll write out the errors to a file we can have a
		# script watching for
		echo "WARNING: Errors in config files - see log for details: $TMPFILE" > /var/run/nagios.configtest
		egrep -i "(^warning|^error)" "$TMPFILE" >> /var/run/nagios.configtest
		chmod 0644 /var/run/nagios.configtest
		cat "$TMPFILE"
    	exit 8
	fi
}

start() {
	test -x $exec || exit 5
	test -f $config || exit 6
	if test "$checkconfig" = "true"; then
		check_config
	fi
    options="-d"
	if test "$use_precached_objects" = "true"; then
        options="$options -u"
    fi
	echo -n $"Starting $prog: "
	# We need to _make sure_ the precache is there and verified
	# Raise priority to make it run better
	daemon --user=$user $exec $options $config
	retval=$?
	echo
	test $retval -eq 0 && touch $lockfile
	return $retval
}

stop() {
	echo -n $"Stopping $prog: "
	killproc -p ${pidfile} -d 10 $exec
	retval=$?
	echo
	test $retval -eq 0 && rm -f $lockfile
	return $retval
}


restart() {
	check_config
	checkconfig="true"
	stop
	start
}

reload() {
	echo -n $"Reloading $prog: "
	killproc -p ${pidfile} $exec -HUP
	RETVAL=$?
	echo
}

force_reload() {
	restart
}

case "$1" in
	start)
		status $prog && exit 0
		$1
		;;
	stop)
		status $prog|| exit 0
		$1
		;;
	restart)
		$1
		;;
	reload)
		status $prog || exit 7
		$1
		;;
	force-reload)
		force_reload
		;;
	status)
		status $prog
		;;
	condrestart|try-restart)
		status $prog|| exit 0
		restart
		;;
	configtest)
		#$nice runuser -s /bin/bash - $user -c "$corelimit >/dev/null 2>&1 ; $exec -vp $config"
		$nice su -s /bin/bash - $user -c "$corelimit >/dev/null 2>&1 ; $exec -vp $config"
		RETVAL=$?
		;;
	*)
		echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
		exit 2
esac

abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Ubuntu 12.04 Nagios 4.0.2 issue w/ /etc/init.d/nagios

Post by abrist »

Have you tried using the script updated by Scott?
http://sourceforge.net/p/nagios/nagiosc ... on-init.in
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked