#ANNEXE 14 - Script d'initialisation Nagios #========================================== # #!/bin/sh NAGIOS_BIN=/usr/local/nagios/bin/nagios NAGIOS_CFG=/usr/local/nagios/etc/nagios.cfg NAGIOS_FLG=" -d " NAGIOS_CHK=" -v " NAGIOS_LCK=/var/nagios/var/nagios.lock NAGIOS_CMD=/var/nagios/var/rw/nagios.cmd # Check we have required binaries and variables if [ ! $NAGIOS_BIN ] || [ ! $NAGIOS_CFG ] || [ ! $NAGIOS_CHK ] || [ ! $NAGIOS_FLG ] || [ ! $NAGIOS_FLG ] || [ ! $NAGIOS_CMD ] then echo "init_nagios.sh configuration error" exit 0 fi test -f $NAGIOS_BIN || exit 0 test -f $NAGIOS_CFG || exit 0 case "$1" in start) if [ -f $NAGIOS_LCK ] && kill -0 `cat $NAGIOS_LCK` 2> /dev/null then echo "Nagios already started..." exit 1 else if [ ! -f $NAGIOS_LCK ] && pidof nagios > /dev/null 2>&1 then echo "Nagios already started but no lockfile..." exit 0 else if pidof nagios > /dev/null 2>&1 then echo "Nagios lockfile exist but no daemon is started..." echo "Deleting lockfile and starting Nagios..." rm -f $NAGIOS_LCK $NAGIOS_CMD $NAGIOS_BIN $NAGIOS_FLG $NAGIOS_CFG exit 1 fi fi fi echo "Starting Nagios..." $NAGIOS_BIN $NAGIOS_FLG $NAGIOS_CFG exit 1 ;; stop) if [ -f $NAGIOS_LCK ] && kill -0 `cat $NAGIOS_LCK` 2> /dev/null then echo "Stopping Nagios..." kill -9 `cat $NAGIOS_LCK` > /dev/null rm -f $NAGIOS_LCK rm -f $NAGIOS_CMD exit 1 else if [ ! -f $NAGIOS_LCK ] && pidof nagios > /dev/null 2>&1 then echo "Nagios seems to be running but no lockfile exists... stopping..." killall nagios rm -f $NAGIOS_LCK rm -f $NAGIOS_CMD exit 0 else if [ -f $NAGIOS_LCK ] then echo "Nagios isn't running but lockfile exists... removing..." rm -f $NAGIOS_LCK rm -f $NAGIOS_CMD exit 0 fi fi fi echo "Nagios is not running ..." ;; restart) $0 stop $0 start exit 1 ;; configtest) $NAGIOS_BIN $NAGIOS_CHK $NAGIOS_CFG exit 1 ;; *) echo "Usage : /etc/init.d/init_nagios.sh {start|stop|restart|configtest}" exit 1 ;; esac exit 0