I am using the openpkg cfengine package and noticed the startup script does
not have start/stop capability for the cfservd and cfenvd processes.  I
created one that does this but I do know how portable it is.  I use base os
ps, grep, and awk to create the process pid files since these programs do
not do this on their own.  

Anyone have a better way of doing this or is this ok and is this something
that can be added to the cfengine package?

Attached is my script.

Aaron


#!/opkg/lib/openpkg/bash /opkg/etc/rc
##
##  rc.cfengine -- Run-Commands
##

%config
    cfengine_enable="$openpkg_rc_def"
    cfengine_log_prolog="true"
    cfengine_log_epilog="true"
    cfengine_log_numfiles="10"
    cfengine_log_minsize="1M"
    cfengine_log_complevel="9"

%common
    cfengine_cfservd_pidfile="/opkg/var/cfengine/cfservd.pid"
    cfengine_cfenvd_pidfile="/opkg/var/cfengine/cfenvd.pid"
    cfengine_signal () {
        [ -f $cfengine_cfservd_pidfile ] \
        && kill -$1 `cat $cfengine_cfservd_pidfile`
        local rc=$?

        [ -f $cfengine_cfenvd_pidfile ] \
        && kill -$1 `cat $cfengine_cfenvd_pidfile` \
        && [ $rc -eq 0 ]
    }

%status -u root -o
    cfengine_usable="unknown"
    cfengine_active="no"
    rcService cfengine enable yes && \
        cfengine_signal 0 && cfengine_active="yes"
    echo "cfengine_enable=\"$cfengine_enable\""
    echo "cfengine_usable=\"$cfengine_usable\""
    echo "cfengine_active=\"$cfengine_active\""

%start -u root
    rcService cfengine enable yes || exit 0
    rcService cfengine active yes && exit 0
    /opkg/sbin/cfservd
    ps -ef | grep [c]fservd | awk '{print $2}' > $cfengine_cfservd_pidfile
    /opkg/sbin/cfenvd
    ps -ef | grep [c]fenvd | awk '{print $2}' > $cfengine_cfenvd_pidfile

%stop -u root
    rcService cfengine enable yes || exit 0
    rcService cfengine active no  && exit 0
    cfengine_signal TERM
    sleep 2
    rm -f $cfengine_cfservd_pidfile $cfengine_cfenvd_pidfile 2>/dev/null || true

%restart -u root
    rcService cfengine enable yes || exit 0
    rcService cfengine active no  && exit 0
    rc cfengine stop start

%daily -u root
    rcService cfengine enable yes || exit 0

    #   rotate logfile
    shtool rotate -f \
        -n ${cfengine_log_numfiles} -s ${cfengine_log_minsize} -d \
        -z ${cfengine_log_complevel} -o opkg-r -g opkg-r -m 644 \
        -P "${cfengine_log_prolog}" \
        -E "${cfengine_log_epilog}" \
        /opkg/var/cfengine/cfengine.log

Reply via email to