NDO2DB startup script for RH (EL) / OEL

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,

About Chris Gralike

Momenteel ben ik manager van de afdeling business continuity bij de zakelijke IT dienstverlener AMIS Services BV. Sinds 2003 ben ik actief in de ICT branche. Tussen 2003 en nu heb ik verschillende rollen vervuld. In de rollen: systeem- en netwerkbeheer, system engineer, servicemanager en nu practice manager ben ik in contact gekomen met uiteenlopende technologieƫn, methodologieƫn, ideeƫn, oplossingen en innovaties. Een rijke ervaring waarmee ik de klanten van Conclusion en AMIS elke dag probeer te ondersteunen. Mijn credo: 'Altijd opzoek een win-win tussen business en technologie.'

Posted on January 19, 2010, in centreon, Linux, Linux Commands, Nagios / Centreon and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink. 4 Comments.

  1. Thanx boss. It’s working.

  2. It works! Just copy the code to a text editor before touching it to the real script to avoid syntax errors. Thanks

  3. Jason Armstrong

    Thanks. Works.šŸ™‚

  1. Pingback: Bad Init Scripts Make Me Angry… | Jared Griffith

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: