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

%config
    flashpolicyd_enable="$openpkg_rc_def"
    flashpolicyd_host="127.0.0.1"
    flashpolicyd_port="843"
    flashpolicyd_log_rotsteps="10"
    flashpolicyd_log_rotminsize="10M"
    flashpolicyd_log_rotcomplevel="9"
    flashpolicyd_log_rotprolog="true"
    flashpolicyd_log_rotepilog="true"

%common
    flashpolicyd_cfgfile="@l_prefix@/etc/flashpolicyd/flashpolicyd.xml"
    flashpolicyd_pidfile="@l_prefix@/var/flashpolicyd/flashpolicyd.pid"
    flashpolicyd_logfile="@l_prefix@/var/flashpolicyd/flashpolicyd.log"
    flashpolicyd_signal () {
        [ -f $flashpolicyd_pidfile ] && kill -$1 `cat $flashpolicyd_pidfile`
    }

%status -u @l_susr@ -o
    flashpolicyd_usable="unknown"
    flashpolicyd_active="no"
    rcService flashpolicyd enable yes && \
        flashpolicyd_signal 0 && flashpolicyd_active="yes"
    echo "flashpolicyd_enable=\"$flashpolicyd_enable\""
    echo "flashpolicyd_usable=\"$flashpolicyd_usable\""
    echo "flashpolicyd_active=\"$flashpolicyd_active\""

%start -u @l_susr@
    rcService flashpolicyd enable yes || exit 0
    rcService flashpolicyd active yes && exit 0
    (   nohup @l_prefix@/sbin/flashpolicyd \
            --host=$flashpolicyd_host \
            --port=$flashpolicyd_port \
            --cfg=$flashpolicyd_cfgfile \
            --log=$flashpolicyd_logfile \
            --uid="@l_nuid@" \
            --gid="@l_ngid@" \
            </dev/null >/dev/null 2>&1 &
        echo $! >$flashpolicyd_pidfile
    ) >/dev/null 2>&1

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

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

