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

%config
    sophie_enable="$openpkg_rc_def"
    sophie_log_prolog="true"
    sophie_log_epilog="true"
    sophie_log_numfiles="10"
    sophie_log_minsize="1M"
    sophie_log_complevel="9"

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

%status -u @l_susr@ -o
    sophie_usable="unknown"
    sophie_active="no"
    rcService sophie enable yes && \
        sophie_signal 0 && sophie_active="yes"
    echo "sophie_enable=\"$sophie_enable\""
    echo "sophie_usable=\"$sophie_usable\""
    echo "sophie_active=\"$sophie_active\""

%start -u @l_susr@
    rcService sophie enable yes || exit 0
    rcService sophie active yes && exit 0
    @l_prefix@/bin/sophie -D

%stop -u @l_susr@
    rcService sophie enable yes || exit 0
    rcService sophie active no  && exit 0
    sophie_signal TERM
    sleep 2

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

%reload -u @l_susr@
    rcService sophie enable yes || exit 0
    rcService sophie active no  && exit 0
    sophie_signal HUP

%daily -u @l_susr@
    rcService sophie enable yes || exit 0
    shtool rotate -f \
        -n ${sophie_log_numfiles} -s ${sophie_log_minsize} -d \
        -z ${sophie_log_complevel} -m 600 -o @l_susr@ -g @l_sgrp@ \
        -P "${sophie_log_prolog}" \
        -E "${sophie_log_epilog} && rc sophie reload" \
        @l_prefix@/var/sophie/sophie.log

