Below a script designed to use the RH . /etc/init.d/functions library. It will use 2 “find” commands to test if it can find the ndo2db binairy and config file. Next it will daemonize the ndo2db process following the Redhat standard init procedure.
This script was written for Redhat enterprise linux using Nagios, Centreon (auto generation of the config)
Edit the “searchdir” for a broader searchscope. In the current code the nagios tree is searched for both the config and the ndo2db binairy.
touch a file in the init.d like so.
touch /etc/init.d/ndodaemon
NExt edit the file and add the code below.
vi /etc/init.d/ndodaemon
Please note the fact that this script uses the /etc/init.d/functions file. Not all linux distro`s deliver this file. Do check its availability in your own distro!
#!/bin/sh
#
# "$Id: ndodaemon.sh,v 0.9 2010/01/19 Chris Exp $"
#
# Startup/shutdown script for the NDO2DB daemon under centreon/nagios.
#
# Linux chkconfig stuff:
#
# chkconfig: 2345 56 10
# description: Startup/shutdown script for NDO2DB Daemon \
# using Centreon / Nagios.
# Source function library.
. /etc/init.d/functions
# Set various vars
#DAEMON=ndo2db;
prog=ndo2db;
SEARCHDIR="/usr/local/nagios"
NDODAEMON=`find $SEARCHDIR -name "ndo2db"`;
NDOCONFIG=`find $SEARCHDIR -name "ndo2db.cfg"`;
#Check if both the ndo daemon and config are found.
#echo -n $"Searching ndo config & binairies : "
if test -f $NDODAEMON
then
if test -f $NDOCONFIG
then
RETVAL=0;
#echo "Files found!";
else
echo "ERROR: Config file not found!";
exit 1;
fi
else
echo "ERROR: ndo2db not found!";
exit 1;
fi
start () {
if test -f "/var/lock/subsys/ndo2db"
then
echo "ndo2db is allready running...";
return 1;
fi
echo -n $"Starting $prog: "
# start daemon
daemon $NDODAEMON -c $NDOCONFIG
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/ndo2db
return $RETVAL
}
stop () {
# stop daemon
echo -n $"Stopping $prog: "
killproc $NDODAEMON
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/ndo2db
}
restart() {
stop
start
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -f /var/lock/subsys/ndo2db ] && restart || :
;;
reload)
echo -n $"Reloading $prog: "
killproc $NDODAEMON -HUP
RETVAL=$?
echo
;;
status)
status $NDODAEMON
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status}"
exit 3
esac
exit $RETVAL
Next if you have chkconfig available as package, you should be able to add the script to the linux init using the commands;
chkconfig --add ndodaemon chkconfig --level 2345 ndodaemon on
start the ndodaemon manually using
/etc/init.d/ndodaemon start #or service ndodaemon start
For those not using Centreon (a shame
) here is an example (default) ndo2db configuration file.
###################################################################
# #
# GENERATED BY CENTREON #
# #
# Developped by : #
# - Julien Mathis #
# - Romain Le Merlus #
# #
# http://www.centreon.com #
# For information : contact@centreon.com #
###################################################################
# #
# Last modification January 19, 2010, 11:11 am #
# By AMIS Services #
# #
###################################################################
ndo2db_user=nagios
ndo2db_group=nagios
socket_type=tcp
socket_name=/var/run/ndo.sock
tcp_port=5668
db_servertype=mysql
db_host=localhost
db_name=centstatus
db_port=3306
db_prefix=nagios_
db_user=centreon
max_timedevents_age=1440
max_systemcommands_age=1440
max_servicechecks_age=1440
max_hostchecks_age=1440
max_eventhandlers_age=1440
Hope this helps!
-Regards,
Tagged: 4, 5, 5.2, 5.3, 5.4, Daemon, EL, Enterprise, for, functions, Init, Linux, ndo, NDO2DB, OEL, Oracle, RH, Script, startup