Bug#283875: [Pkg-nagios-devel] Bug#283875: nagios reload fails too

Olaf van der Spek Olaf van der Spek <OvdSpek@LIACS.NL>, 283875@bugs.debian.org
Thu, 02 Dec 2004 15:56:39 +0100


sean finney wrote:
> On Thu, Dec 02, 2004 at 12:36:16PM +0100, Olaf van der Spek wrote:
> 
>>I'm afraid I can't reproduce the bug anymore.
>>I guess a couple of reboots and nagios restarts have fixed it.
> 
> 
> could it be that the new init script was unable to stop the old
> nagios process from the previous version of the package, and once
> you killed it things were okay?

Hmm, now it happened again:
debian:/etc/init.d# cat nagios
#! /bin/sh
#
# skeleton      example file to build /etc/init.d/ scripts.
#               This file should be used to construct scripts for 
/etc/init.d.
#
#               Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#               Modified for Debian GNU/Linux
#               by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:      @(#)skeleton  1.8  03-Mar-1998  miquels@cistron.nl
#
# This file was automatically customized by dh-make on Mon, 17 Jan 2000 
19:30:36 +0000
# Hacked into netsaint shape by bjb.

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nagios
NAME=nagios
DESC=nagios
NICENESS=5
NAMEDPIPE=/var/run/nagios/nagios.cmd
PIDFILE=/var/run/nagios/nagios.pid
CONFIG=/etc/nagios/nagios.cfg

test -f $DAEMON || exit 0

set -e
set -x
#
# Is this function useful at all?
# start-stop-daemon should handle this work!
#
check_started () {
     if [ -f /etc/nagios/check_nagios_db ]; then
         if /etc/nagios/check_nagios_db > /dev/null; then
             return 0    # Is started
         else
             return 1    # Isn't started
         fi
     elif [ -f /usr/lib/nagios/plugins/check_nagios ]; then
         if /usr/lib/nagios/plugins/check_nagios -F 
/var/log/nagios/status.log -e 5 -C 'nagios' > /dev/null; then
             return 0    # Is started
         else
             return 1    # Isn't started
         fi
     elif [ -f /usr/lib/netsaint/plugins/check_netsaint ]; then
         if /usr/lib/netsaint/plugins/check_netsaint -F 
/var/log/nagios/status.log -e 5 -C 'nagios' > /dev/null; then
             return 0    # Is started
         else
             return 1    # Isn't started
         fi
     elif [ -f $PIDFILE ]; then
         # Try discovering if nagios is alive checking its pid
         if kill -CHLD $( cat $PIDFILE ) ; then
             return 1    # Isn't started
         else
             return 0    # Is started
         fi
     else
         return 1        # Isn't started
     fi
}

get_config () {
     set -- `grep ^$1 $CONFIG | sed 's@=@ @'`
     echo $2
}

check_config () {
     if $DAEMON -v $CONFIG >/dev/null 2>&1 ; then
         # First get the user/group etc Nagios is running as
         nagios_user=`get_config nagios_user`
         nagios_group=`get_config nagios_group`
         log_file=`get_config log_file`
         log_dir=`dirname $log_file`

         # Chown the log directory to this user/group so that
         # Nagios can write there.
         chown -R $nagios_user.$nagios_group $log_dir

         return 0    # Config is ok
     else
         # config is not okay, so let's barf the error to the user
         $DAEMON -v $CONFIG
         return 1    # Config not ok
     fi
}

check_named_pipe () {
     if [ -p $NAMEDPIPE ]; then
         return 1   # a named pipe exists
     else
         return 0   # no named pipe exists
     fi
}

case "$1" in
   start)
         echo -n "Starting $DESC: "
         if ! check_started; then
             if ! check_named_pipe; then
                 echo "named pipe exists - removing"
                 rm -f $NAMEDPIPE
             fi

             if check_config; then
                 rm -f $NAMEDPIPE
             start-stop-daemon --start --quiet \
                         --nicelevel $NICENESS \
                     --pidfile $PIDFILE \
                     --make-pidfile --background --exec $DAEMON -- $CONFIG
                 echo "$NAME."
             else
                 echo "errors in config!"
             fi
         else
             echo "already running"
         fi
         ;;
   stop)
         echo -n "Stopping $DESC: "
         start-stop-daemon --stop --quiet --pidfile $PIDFILE \
                 --oknodo --exec $DAEMON
         echo "$NAME."
         rm -f $PIDFILE
         rm -f $NAMEDPIPE
         ;;
   reload|force-reload)
         echo "Reloading $DESC configuration files."
         # Check first
         if check_config; then
             if check_started; then
                 start-stop-daemon --stop --signal 1 --quiet --pidfile \
                     $PIDFILE --exec $DAEMON
             else
                 echo "Not running."
             fi
         else
             echo "Errors in config file. Not reloading."
         fi
         ;;
   restart)
         echo -n "Restarting $DESC: "
         $0 stop
         sleep 2
         $0 start
         ;;
   *)
         N=/etc/init.d/$NAME
         echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
         exit 1
         ;;
esac

exit 0
debian:/etc/init.d# ./nagios reload
+ case "$1" in
+ echo 'Reloading nagios configuration files.'
Reloading nagios configuration files.
+ check_config
+ /usr/sbin/nagios -v /etc/nagios/nagios.cfg
++ get_config nagios_user
+++ grep '^nagios_user' /etc/nagios/nagios.cfg
+++ sed 's@=@ @'
++ set -- nagios_user nagios
++ echo nagios
+ nagios_user=nagios
++ get_config nagios_group
+++ grep '^nagios_group' /etc/nagios/nagios.cfg
+++ sed 's@=@ @'
++ set -- nagios_group nagios
++ echo nagios
+ nagios_group=nagios
++ get_config log_file
+++ grep '^log_file' /etc/nagios/nagios.cfg
+++ sed 's@=@ @'
++ set -- log_file /var/log/nagios/nagios.log
++ echo /var/log/nagios/nagios.log
+ log_file=/var/log/nagios/nagios.log
++ dirname /var/log/nagios/nagios.log
+ log_dir=/var/log/nagios
+ chown -R nagios.nagios /var/log/nagios
+ return 0
+ check_started
+ '[' -f /etc/nagios/check_nagios_db ']'
+ '[' -f /usr/lib/nagios/plugins/check_nagios ']'
+ '[' -f /usr/lib/netsaint/plugins/check_netsaint ']'
+ '[' -f /var/run/nagios/nagios.pid ']'
++ cat /var/run/nagios/nagios.pid
+ kill -CHLD 2247
+ return 1
+ echo 'Not running.'
Not running.
+ exit 0
debian:/etc/init.d# ps aux|grep nagios
nagios    2247  0.0  0.5   3316  1420 ?        SNs  11:53   0:02 
/usr/sbin/nagios /etc/nagios/nagios.cfg
root      4024  0.0  0.1   1572   468 pts/1    S+   13:44   0:00 grep nagios
debian:/etc/init.d#