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

%config
    msntp_enable="$openpkg_rc_def"
    msntp_log_prolog="true"
    msntp_log_epilog="true"
    msntp_log_numfiles="10"
    msntp_log_minsize="1M"
    msntp_log_complevel="9"

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

%status -u @l_susr@ -o
    msntp_usable="no"
    msntp_active="no"
    rcService msntp enable yes && \
        msntp_signal 0 && msntp_active="yes"
    echo "msntp_enable=\"$msntp_enable\""
    echo "msntp_usable=\"$msntp_usable\""
    echo "msntp_active=\"$msntp_active\""

%start -u @l_susr@
    rcService msntp enable yes || exit 0
    rcService msntp active yes && exit 0
    @l_prefix@/bin/msntp -S &
    echo $! >$msntp_pidfile

%stop -u @l_susr@
    rcService msntp enable yes || exit 0
    rcService msntp active no && exit 0
    msntp_signal TERM
    rm -f $msntp_pidfile 2>/dev/null || true

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

%daily -u @l_susr@
    rcService msntp enable yes || exit 0
    shtool rotate -f \
        -n ${msntp_log_numfiles} -s ${msntp_log_minsize} -d \
        -z ${msntp_log_complevel} -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "${msntp_log_prolog}" \
        -E "${msntp_log_epilog}; rc msntp restart" \
        @l_prefix@/var/msntp/msntp.log

