Forum: Cfengine Help
Subject: Re: Cfengine Help: cf-execd: is daemon or cron better?
Author: ro
Link to topic: https://cfengine.com/forum/read.php?3,19554,19561#msg-19561

My line in /etc/crontab looks like this:


*/5 *    * * *   root   /usr/local/sbin/watchdog.cfengine


The script that is called via cron contains:


/bin/sh
processname="cf-execd"

if ! [ `pidof $processname` ] ; then
        $processname
        logger -t WATCHDOG "$processname not running, tried to restart 
$processname"
fi



The init.d script is as follows:


#! /bin/sh
#####################################################################
# /etc/init.d/cfengine3 (Client)
#
# Init script for cfengine3
# 
#         This file is protected by cfengine. Whatever you do,
#             it will be changed back to a promising state.
#####################################################################
#
### BEGIN INIT INFO
# Provides:          cfengine3
# Required-Start:    $local_fs $remote_fs $network $time
# Required-Stop:     $local_fs $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: GNU configuration engine
# Description:       Tool for configuring and maintaining network machines
### END INIT INFO
#
# chkconfig: 2345 60 40
# description: Starts the cfengine daemons for remote and periodic \
#    execution of cfengine and for environment monitoring.
#

set -e

CFEXECD=/usr/local/sbin/cf-execd
CFSERVD=/usr/local/sbin/cf-serverd
CFENVD=/usr/local/sbin/cf-monitord

PATH=/sbin:/bin:/usr/sbin:/usr/bin

# Has the package been 'removed' but not purged?
test -f $CFEXECD || exit 0

. /lib/lsb/init-functions

# Source the config file
DEFAULT=/etc/default/cfengine3
if [ -f $DEFAULT ]; then
    . $DEFAULT
else
    RUN_CF_SERVERD=1
    RUN_CF_EXECD=1
    RUN_CF_MONITORD=1
fi

# Return-status
RETVAL=0

if /sbin/start-stop-daemon -V >/dev/null 2>&1; then
    # start-stop-daemon runs OK
    SSD=1
else
    # Probably not a Debian system
    SSD=0
fi

ctrl_daemon () {
    # Usage: ctrl_daemon    []
    #  where  is 'start' or 'stop'. 'stop' args are passed to
    #  start-stop-daemon.

    OPERATION=$1; shift
    DAEMON=$1; shift
    DAEMONNAME=$(basename $DAEMON)
    case $OPERATION in
        "start")
            set +e
            if [ "$SSD" = "1" ]; then
                CMD="start-stop-daemon --start --quiet --exec $DAEMON -- $@"
            else
                CMD="$DAEMON $@"
            fi
            log_progress_msg "$DAEMONNAME"
            $CMD || RETVAL=1
            set -e
            ;;
        "stop")
            set +e
            log_progress_msg "$DAEMONNAME"
            DAEMON=`basename $DAEMON`
            if [ "$SSD" = "1" ]; then
                start-stop-daemon -o --stop --retry 5 --quiet --name "$DAEMON" 
"$@"
            else
                pkill `basename $DAEMON` 2>/dev/null
            fi
            test $? = "0" || RETVAL=1
            set -e
            ;;
        "*")
            log_warning_msg "cfengine3: Invalid operation, must be 'start' or 
'stop'."
            ;;
    esac
}


case "$1" in
    start)
        RETVAL=0
        log_daemon_msg "Starting cfengine3"
        case "$RUN_CF_MONITORD $RUN_CF_EXECD $RUN_CF_SERVERD" in
            *1*) ;;
            *) exit 0;;
        esac
        if [ "$RUN_CF_MONITORD" = "1" ]; then
            ctrl_daemon start "$CFENVD"
        fi
        if [ "$RUN_CF_EXECD" = "1" ]; then
            ctrl_daemon start "$CFEXECD"
        fi
        if [ "$RUN_CF_SERVERD" = "1" ]; then
            ctrl_daemon start "$CFSERVD"
        fi
        log_end_msg $RETVAL
        ;;
   
    stop)
        RETVAL=0
        log_daemon_msg "Stopping cfengine3"
        if [ "$RUN_CF_MONITORD" = "1" ]; then
            ctrl_daemon stop "$CFENVD"
        fi
        if [ "$RUN_CF_EXECD" = "1" ]; then
            ctrl_daemon stop "$CFEXECD"
        fi
        if [ "$RUN_CF_SERVERD" = "1" ]; then
            ctrl_daemon stop "$CFSERVD"
        fi
        log_end_msg $RETVAL
        ;;
   
    reload)
        ;;
   
    restart|force-reload)
        $0 stop
        sleep 1
        $0 start
        ;;
   
    *)
        N=/etc/init.d/cfengine3
        echo "Usage: $N {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0


And finally, here's the /etc/default/cfengine3:


#####################################################################
# /etc/default/cfengine3 (Client)
#
# Cfengine3 default configuration
# 
#         This file is protected by cfengine. Whatever you do,
#             it will be changed back to a promising state.
#####################################################################


# Set variable to 1 to start the daemon; 0 otherwise.
RUN_CF_SERVERD=0
RUN_CF_EXECD=1
RUN_CF_MONITORD=0


I got this somewhere off the internet, and I had zero problems so far.

Cheers,
Robert

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to