Tuesday, November 6, 2012

Quick and easy init script

Quick and easy init script - puppetwatchdog

This is the init script that developed to launch puppetwatchdog in order to gather all the facter values from the puppet agent. Then, it will bump it into a sqlite3 database for further data analysis.

Puppetwatchdog should be setup at puppetmaster.

If you want to write a quick and easy daemon script at /etc/init.d/*. You can pretty much take a look at this code.


#
# chkconfig: 2345 90 60
# description: This is a watchdog where is collected \
#              all the puppet yaml files and inject it to a db
##### END INIT INFO

RETVAL=0
prog="puppet_watchdogd"
exec=/usr/bin/puppet_watchdogd
lockfile=/var/lock/subsys/puppet_watchdogd

# Source function library.
. /etc/rc.d/init.d/functions

start() {
        if [ $UID -ne 0 ]; then
                echo "User has insufficient privilege."
                exit 4
        fi

        [ -x $exec ] || exit 5
        echo -n $"Starting $prog: "
        daemon "$prog 2>&1 &"
        retval=$?
        echo
        [ $retval -eq 0 ] && touch $lockfile
}


stop() {
        if [ $UID -ne 0 ] ; then
                echo "User has insufficient privilege."
                exit 4
        fi

        echo -n $"Stopping $prog: "
        killproc $exec
        retval=$?
        echo
        [ $retval -eq 0 ] && rm -fr $lockfile
}


restart() {
        stop
        start
}

case "$1" in
        start)
                start
        ;;
        stop)
                stop
        ;;
        restart)
                restart
        ;;
        *)
        echo $"Usage $0 {start|stop|restart}"
        exit 2
esac
exit $?




No comments: