Codebase list icinga / debian/1.6.1-2 rc.ido2db.in
debian/1.6.1-2

Tree @debian/1.6.1-2 (Download .tar.gz)

rc.ido2db.in @debian/1.6.1-2raw · history · blame

#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          ido2db
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Icinga IDO2DB Initscript
# Description: 	     Icinga Data Out Daemon
### END INIT INFO

# chkconfig: 345 99 01
#
# File : ido2db
#
# Author : Jorge Sanchez Aymar (jsanchez@lanchile.cl)
#
# Changelog :
#
# 1999-07-09 Karl DeBisschop <kdebisschop@infoplease.com>
#  - setup for autoconf
#  - add reload function
# 1999-08-06 Ethan Galstad <egalstad@nagios.org>
#  - Added configuration info for use with RedHat's chkconfig tool
#    per Fran Boon's suggestion
# 1999-08-13 Jim Popovitch <jimpop@rocketship.com>
#  - added variable for nagios/var directory
#  - cd into nagios/var directory before creating tmp files on startup
# 1999-08-16 Ethan Galstad <egalstad@nagios.org>
#  - Added test for rc.d directory as suggested by Karl DeBisschop
# 2000-07-23 Karl DeBisschop <kdebisschop@users.sourceforge.net>
#  - Clean out redhat macros and other dependencies
# 2003-01-11 Ethan Galstad <egalstad@nagios.org>
#  - Updated su syntax (Gary Miller)
# 2009-07-11 Hendrik Bäcker <andurin@process-zero.de>
#  - Rewrite ido2db init script, inspired by Sascha Runschke
#
#

servicename=@ido2db_name@
prefix=@prefix@
exec_prefix=${prefix}
Ido2dbBin=@bindir@/@ido2db_name@
Ido2dbCfgFile=@sysconfdir@/ido2db.cfg
Ido2dbVarDir=@localstatedir@
Ido2dbRunFile=$Ido2dbVarDir/ido2db.lock
Ido2dbSockFile=$Ido2dbVarDir/ido.sock
Ido2dbLockDir=/var/lock/subsys
Ido2dbLockFile=@ido2db_name@
Ido2dbUser=@icinga_user@
Ido2dbGroup=@icinga_grp@

#add ocilib lib path to link at runtime if enabled
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@ido2db_runtime@
export LD_LIBRARY_PATH


# load extra environment variables
if [ -f /etc/sysconfig/ido2db ]; then
        . /etc/sysconfig/ido2db
fi


# 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


# Check that ido2db exists.
if [ ! -f $Ido2dbBin ]; then
    echo "Executable file $Ido2dbBin not found.  Exiting."
    exit 1
fi

# Check that ido2db.cfg exists.
if [ ! -f $Ido2dbCfgFile ]; then
    echo "Configuration file $Ido2dbCfgFile not found.  Exiting."
    exit 1
fi

## helper functions ##

status_ido2db ()
{

	if ps -p $Ido2dbPID > /dev/null 2>&1; then
		return 0
	else
		return 1
        fi

        return 1
}

printstatus_ido2db()
{
	if status_ido2db $1 $2; then
		echo "$servicename (pid $Ido2dbPID) is running..."
	elif test $? == 2; then
		echo "$servicename is not running but subsystem locked"
	else
		echo "$servicename is not running"
	fi
}


killproc_ido2db ()
{
	kill $2 $Ido2dbPID

}

killproc9_ido2db ()
{
        kill -9 $Ido2dbPID

}

pid_ido2db ()
{

	if test ! -f $Ido2dbRunFile; then
		echo "ido2db not running. PID file $Ido2dbRunFile not found"
		exit 1
	fi

	Ido2dbPID=`head -n 1 $Ido2dbRunFile`
}

## MAIN ##
# See how we were called.
case "$1" in

	start)
		#check if ido2db is already running
		$0 status > /dev/null
		if [ $? -eq 0 ]; then
			pid_ido2db
			# check if pid can be found running
			if status_ido2db > /dev/null; then
				echo "$servicename is already running. PID: $Ido2dbPID"
				exit 1
			else
				echo "$servicename PID $Ido2dbPID not running. Removing lockfile."
				rm -f $Ido2dbStatusFile $Ido2dbRunFile $Ido2dbLockDir/$Ido2dbLockFile $Ido2dbCommandFile
			fi
		fi
		printf "Starting $servicename:"
		# remove leftover sockfile, from a system crash
		rm -f $Ido2dbSockFile
		touch $Ido2dbRunFile
		chown $Ido2dbUser:$Ido2dbGroup $Ido2dbRunFile
		$Ido2dbBin -c $Ido2dbCfgFile
		if [ -d $Ido2dbLockDir ]; then touch $Ido2dbLockDir/$Ido2dbLockFile; fi
		echo " done."
		exit 0
		;;

	stop)
		printf "Stopping $servicename: "

		pid_ido2db
		killproc_ido2db ido2db

 		# now we have to wait for ido2db to exit and remove its
 		# own Ido2dbRunFile, otherwise a following "start" could
 		# happen, and then the exiting ido2db will remove the
 		# new Ido2dbRunFile, allowing multiple ido2db daemons
 		# to (sooner or later) run - John Sellens
 		for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
 		    if status_ido2db > /dev/null; then
 			printf '.'
 			sleep 1
 		    else
 			break
 		    fi
 		done
 		if status_ido2db > /dev/null; then
 		    echo ''
 		    echo "Warning - $servicename did not exit in a timely manner. Sending kill -9"
		    kill9proc_ido2db
 		else
 		    echo "done."
		    rm -f $Ido2dbStatusFile $Ido2dbRunFile $Ido2dbLockDir/$Ido2dbLockFile $Ido2dbCommandFile
 		fi

		;;

        status)
		pid_ido2db
		printstatus_ido2db ido2db
                ;;

	restart)
		$0 stop
		$0 start
		;;

	*)
		echo "Usage: $servicename {start|stop|restart|status}"
		exit 1
		;;

esac
  
# End of this script