Is functional, there is a bug in the start portion that i still need to fix. But it will start the deamon correctly and if you use the “service ndodaemon rewrite-lock” the status and stop functions will also work correctly.
#!/bin/sh
#
# chkconfig: 345 90 01
# description: Nagios NDO Utils Deamon
# ./etc/init.d/ndodaemonprefix=/usr/sbin
Bin=ndo2db
NdoBin=$prefix/$Bin
NdoUsr=root
NdoConf=/usr/local/nagios/etc/ndo2db.cfg
RunFile=/usr/local/nagios/var/ndo2db.lock#check if ndobin exists
if [ ! -f $NdoBin ]; then
echo "NDO Binairy doesnt exist!"
exit 1
fi#check if ndoConfig exists
if [ ! -f $NdoConf ]; then
echo "NDO Config file not found!"
exit 1
ficase $1 in
start)
if test -f $RunFile; then
echo "NDO Deamon allready started"
exit 1
else
echo -n "Starting the NDO Deamon:"
$NdoBin -c $NdoConf & > /dev/null 2>&1;if [ $? -eq 0 ]; then
for i in 1 2 3 4 5 6 7 8 9 10 ; do
echo -n ".";
sleep 1
done
P=`ps -C $Bin -o pid | grep -P [0-9]`echo "Done."
exit 0
else
echo "Failed to start the deamon, check the config file!"
exit 1
fi
fi
;;stop)
if test -f $RunFile; then
#make sure we have both services!
`ps -C $Bin -o pid | grep -P [0-9] > $RunFile`
#Get first PID
ndo1PID=`head -n 1 $RunFile`;
#Get 2nd PID
ndo2PID=`tail -n 1 $RunFile`;
echo $ndo1PID
echo $ndo2PID
#need to make this a bit more logic, but it works for the moment....
kill $ndo1PID > /dev/null 2>&1;
kill $ndo2PID > /dev/null 2>&1;
rm $RunFile > /dev/null
if [ $? -eq 0 ]; then
echo "Done."
exit 0;
else
echo "Failed."
exit 1
fi
else
echo "No NDO deamon to stop!"
exit 1;
fi;;
rewrite-lock)
ps -C $Bin -o pid | grep -P [0-9] > $RunFile
;;status)
if test -f $RunFile; then
#We have a runfile, so we check based on PID
ndo1PID=`head -n 1 $RunFile`;
ndo2PID=`tail -n 1 $RunFile`;
#Process Parent NDO deamon
if [ $ndo1PID > 0 ]; then
ps -p $ndo1PID > /dev/null 2>&1;
if [ $? -eq 0 ]; then
Status1="NDO Parent (PID $ndo1PID) is alive!"
else
Status1="NDO Parent (PID $ndo1PID) not alive, remove lock file then check for orphan processes then restart deamon."
fi
else
Status1="NDO Parent (PID $ndo1PID) not alive!"
fiif [ $ndo2PID > 0 ]; then
ps -p $ndo2PID > /dev/null 2>&1;
if [ $? -eq 0 ]; then
Status2="NDO Child (PID $ndo2PID) is alive!"
else
Status2="NDO Child (PID $ndo2PID) not alive!"
fi
else
Status2="NDO child (PID $ndo2PID) not alive!"
fi
echo $Status1
echo $Status2
exit 0
else
#We dont have a Runfile so lets see if someone started it manually.
ps -C $Bin > /dev/null 2>&1;
if [ $? -eq 0 ]; then
echo "NDO process seems to be manually started!"
exit 1
else
echo "NDO Deamon is not running."
exit 1
fi
fi
;;*)
echo "Usage: $0 {start|stop|status|rewrite-lock}"
exit 1
;;
esac
Tagged: auto, bash, centreon, chkconfig, custom, init.d, Linux, monitoring, nagios, ndo, ndo utils, NDO2DB, Network, Script, startup
