#!/bin/sh # ### BEGIN INIT INFO # Provides: ndo2db # Required-Start: mysqld nagios # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Nagios NDO2DB Initscript # Description: Nagios Data Out Daemon ### END INIT INFO # chkconfig: 2345 99 01 # # File : ndo2db # # Author : Jorge Sanchez Aymar (jsanchez@lanchile.cl) # # Changelog : # # 1999-07-09 Karl DeBisschop # - setup for autoconf # - add reload function # 1999-08-06 Ethan Galstad # - Added configuration info for use with RedHat's chkconfig tool # per Fran Boon's suggestion # 1999-08-13 Jim Popovitch # - added variable for nagios/var directory # - cd into nagios/var directory before creating tmp files on startup # 1999-08-16 Ethan Galstad # - Added test for rc.d directory as suggested by Karl DeBisschop # 2000-07-23 Karl DeBisschop # - Clean out redhat macros and other dependencies # 2003-01-11 Ethan Galstad # - Updated su syntax (Gary Miller) # 2009-07-11 Hendrik Bker # - Rewrite ndo2db init script, inspired by Sascha Runschke # 2012-10-11 Check for sock-file before start (unexpected shutdowns) by Stefan Rueetschli # status_ndo2db () { pid_ndo2db if ps -p $Ndo2dbPID > /dev/null 2>&1; then # ndo2db is already running... return 0 else if test -S $Ndo2dbSockFile; then # ndo2db is not running but a socket file exists return 2 else # ndo2db is not running return 1 fi fi return 1 } printstatus_ndo2db() { if status_ndo2db $1 $2; then echo "$servicename (pid $Ndo2dbPID) is running..." elif test $? == 2; then echo "$servicename is not running but subsystem locked" else echo "$servicename is not running" fi } killproc_ndo2db () { kill $2 $Ndo2dbPID } pid_ndo2db () { if test ! -f $Ndo2dbRunFile; then return 1 fi Ndo2dbPID=`head -n 1 $Ndo2dbRunFile` return 0 } # Source function library # Solaris doesn't have an rc.d directory, so do a test first if [ -f /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions elif [ -f /etc/init.d/functions ]; then . /etc/init.d/functions fi servicename=ndo2db #prefix=/usr #exec_prefix=/usr Ndo2dbBin=/usr/local/nagios/bin/ndo2db-3x Ndo2dbCfgFile=/usr/local/nagios/etc/ndo2db.cfg Ndo2dbVarDir=/usr/local/nagios/var Ndo2dbRunFile=$Ndo2dbVarDir/ndo2db.pid Ndo2dbLockDir=/var/lock/subsys Ndo2dbLockFile=ndo2db Ndo2dbSockFile=$Ndo2dbVarDir/ndo2db.sock Ndo2dbUser=nagios Ndo2dbGroup=nagios # Check that ndo2db exists. if [ ! -f $Ndo2dbBin ]; then echo "Executable file $Ndo2dbBin not found. Exiting." exit 1 fi # Check that ndo2db.cfg exists. if [ ! -f $Ndo2dbCfgFile ]; then echo "Configuration file $Ndo2dbCfgFile not found. Exiting." exit 1 fi # See how we were called. case "$1" in start) status_ndo2db if [ $? -eq 0 ]; then echo "$servicename already started..." exit 1 fi status_ndo2db if [ $? -eq 2 ]; then echo "$servicename is not running but locked. Trying delete sock-file and start..." rm -f $Ndo2dbSockFile fi echo -n "Starting $servicename: " $Ndo2dbBin -c $Ndo2dbCfgFile if [ -d $Ndo2dbLockDir ]; then touch $Ndo2dbLockDir/$Ndo2dbLockFile; chown $Ndo2dbUser:$Ndo2dbGroup $Ndo2dbLockDir/$Ndo2dbLockFile fi echo "done." exit 0 ;; stop) status_ndo2db if ! [ $? -eq 0 ]; then echo "$servicename was not running... could not stop" exit 1 fi echo -n "Stopping $servicename: " pid_ndo2db killproc_ndo2db ndo2db # now we have to wait for ndo2db to exit and remove its # own Ndo2dbRunFile, otherwise a following "start" could # happen, and then the exiting ndo2db will remove the # new Ndo2dbRunFile, allowing multiple ndo2db daemons # to (sooner or later) run - John Sellens #echo -n 'Waiting for ndo2db to exit .' for i in 1 2 3 4 5 6 7 8 9 10 ; do if status_ndo2db 2>/dev/null; then echo -n '.' sleep 1 else break fi done if status_ndo2db 2>/dev/null; then echo '' echo 'Warning - $servicename did not exit in a timely manner' else echo "done." fi rm -f $Ndo2dbRunFile $Ndo2dbLockDir/$Ndo2dbLockFile $Ndo2dbSockFile ;; status) printstatus_ndo2db ;; restart) $0 stop $0 start ;; *) echo "Usage: $servicename {start|stop|restart|status}" exit 1 ;; esac