#!@l_prefix@/lib/openpkg/bash @l_prefix@/etc/rc
##
##  rc.postfix-mailgraph -- Run-Commands
##

%config
    postfix_mailgraph_enable="$openpkg_rc_def"

%common
    postfix_mailgraph_pidfile="@l_prefix@/var/postfix-mailgraph/run/mailgraph.pid"
    postfix_mailgraph_signal () {
        [ -f $postfix_mailgraph_pidfile ] \
        && kill -$1 `cat $postfix_mailgraph_pidfile`
    }

%status -u @l_susr@ -o
    postfix_mailgraph_usable="unknown"
    postfix_mailgraph_active="no"
    rcService postfix_mailgraph enable yes && \
        postfix_mailgraph_signal 0 && postfix_mailgraph_active="yes"
    echo "postfix_mailgraph_enable=\"$postfix_mailgraph_enable\""
    echo "postfix_mailgraph_usable=\"$postfix_mailgraph_usable\""
    echo "postfix_mailgraph_active=\"$postfix_mailgraph_active\""

%start -u @l_susr@
    rcService postfix-mailgraph enable yes || exit 0
    @l_prefix@/sbin/mailgraph --daemon

%stop -u @l_susr@
    rcService postfix-mailgraph enable yes || exit 0
    postfix_mailgraph_signal TERM

%restart -u @l_susr@
    rcService postfix-mailgraph enable yes || exit 0
    postfix_mailgraph_signal TERM
    sleep 2
    @l_prefix@/sbin/mailgraph --daemon

