#!@l_prefix@/bin/openpkg rc
##
##  rc.smokeping -- Run-Commands
##

%config
    smokeping_enable="$openpkg_rc_def"

%common
    smokeping_pidfile="@l_prefix@/var/smokeping/smokeping.pid"
    smokeping_signal () {
        [ -f $smokeping_pidfile ] && kill -$1 `cat $smokeping_pidfile`
    }

%status -u @l_susr@ -o
    smokeping_usable="no"
    smokeping_active="no"
    @l_prefix@/sbin/smokeping --check >/dev/null && smokeping_usable="yes"
    rcService smokeping enable yes && \
        smokeping_signal 0 && smokeping_active="yes"
    echo "smokeping_enable=\"$smokeping_enable\""
    echo "smokeping_usable=\"$smokeping_usable\""
    echo "smokeping_active=\"$smokeping_active\""

%start -u @l_susr@
    rcService smokeping enable yes || exit 0
    rcService smokeping active yes && exit 0
    @l_prefix@/sbin/smokeping >/dev/null

%stop -u @l_susr@
    rcService smokeping enable yes || exit 0
    rcService smokeping active no  && exit 0
    smokeping_signal TERM
    sleep 2
    rm -f $smokeping_pidfile >/dev/null 2>&1 || true

%restart -u @l_susr@
    rcService smokeping enable yes || exit 0
    rcService smokeping active no  && exit 0
    rc smokeping stop start

