pnp4nagios/scripts/rc.npcd.in

163 lines
3.5 KiB
Plaintext
Raw Permalink Normal View History

2017-05-20 15:26:21 +02:00
#!@SHELL@
2017-10-20 17:10:51 +02:00
#
2017-05-20 15:26:21 +02:00
### BEGIN INIT INFO
# Provides: npcd
2017-10-20 17:10:51 +02:00
# Required-Start:
# Required-Stop:
2017-05-20 15:26:21 +02:00
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: @PKG_NAME@ NPCD Daemon Version @PKG_VERSION@
# Description: Nagios Performance Data C Daemon
### END INIT INFO
# chkconfig: 345 99 01
#
# File : npcd
#
2017-10-20 17:10:51 +02:00
2017-05-20 15:26:21 +02:00
servicename=@npcd_name@
prefix=@prefix@
exec_prefix=${prefix}
NpcdBin=@bindir@/@npcd_name@
NpcdCfgFile=@sysconfdir@/npcd.cfg
NpcdVarDir=@localstatedir@
NpcdRunFile=/var/run/npcd.pid
NpcdLockDir=/var/lock/subsys
NpcdLockFile=@npcd_name@
NpcdUser=@nagios_user@
NpcdGroup=@nagios_grp@
status_npcd (){
pid_npcd
if ps -p $NpcdPID > /dev/null 2>&1; then
return 0
else
if test -f $NpcdLockDir/$NpcdLockFile; then
return 2
else
return 1
fi
fi
return 1
}
printstatus_npcd(){
if status_npcd $1 $2; then
echo "$servicename (pid $NpcdPID) is running..."
exit 0
elif test $? -eq 2; then
echo "$servicename is not running but subsystem locked"
2017-10-20 17:10:51 +02:00
exit 3
2017-05-20 15:26:21 +02:00
else
echo "$servicename is not running"
2017-10-20 17:10:51 +02:00
exit 3
2017-05-20 15:26:21 +02:00
fi
}
killproc_npcd (){
kill $2 $NpcdPID
}
pid_npcd (){
if test ! -f $NpcdRunFile; then
return 1
fi
NpcdPID=`head -n 1 $NpcdRunFile`
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
# Check that npcd exists.
if [ ! -f $NpcdBin ]; then
echo "Executable file $NpcdBin not found. Exiting."
exit 1
fi
# Check that npcd.cfg exists.
if [ ! -f $NpcdCfgFile ]; then
echo "Configuration file $NpcdCfgFile not found. Exiting."
exit 1
fi
2017-10-20 17:10:51 +02:00
2017-05-20 15:26:21 +02:00
# See how we were called.
case "$1" in
start)
status_npcd
if [ $? -eq 0 ]; then
echo "$servicename already started..."
2017-10-20 17:10:51 +02:00
exit 0
2017-05-20 15:26:21 +02:00
fi
echo -n "Starting $servicename:"
touch $NpcdRunFile
chown $NpcdUser:$NpcdGroup $NpcdRunFile
$NpcdBin -d -f $NpcdCfgFile
if [ -d $NpcdLockDir ]; then touch $NpcdLockDir/$NpcdLockFile; fi
echo " done."
exit 0
;;
stop)
status_npcd
if ! [ $? -eq 0 ]; then
echo "$servicename was not running... could not stop"
2017-10-20 17:10:51 +02:00
exit 0
2017-05-20 15:26:21 +02:00
fi
echo -n "Stopping $servicename: "
pid_npcd
killproc_npcd npcd
# now we have to wait for npcd to exit and remove its
# own NpcdRunFile, otherwise a following "start" could
# happen, and then the exiting npcd will remove the
# new NpcdRunFile, allowing multiple npcd daemons
# to (sooner or later) run - John Sellens
#echo -n 'Waiting for npcd to exit .'
for i in 1 2 3 4 5 6 7 8 9 10 ; do
if status_npcd > /dev/null; then
echo -n '.'
sleep 1
else
break
fi
done
if status_npcd > /dev/null; then
echo ''
echo 'Warning - $servicename did not exit in a timely manner'
else
echo 'done.'
fi
2017-10-20 17:10:51 +02:00
rm -f $NpcdLockDir/$NpcdLockFile
2017-05-20 15:26:21 +02:00
;;
status)
printstatus_npcd
;;
reload)
$0 restart
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $servicename {start|stop|restart|status}"
exit 1
;;
esac
2017-10-20 17:10:51 +02:00
2017-05-20 15:26:21 +02:00
# End of this script