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

%config
    klish_enable="$openpkg_rc_def"
    klish_bind="127.0.0.1:110"
    klish_log_prolog="true"
    klish_log_epilog="true"
    klish_log_numfiles="10"
    klish_log_minsize="1M"
    klish_log_complevel="9"

%common
    klish_socket="@l_prefix@/var/klish/klish.socket"
    klish_pidfile="@l_prefix@/var/klish/klish.pid"
    klish_signal () {
        [ -f $klish_pidfile ] && kill -$1 `cat $klish_pidfile`
    }

%status -u @l_susr@ -o
    klish_usable="unknown"
    klish_active="no"
    rcService klish enable yes && \
        klish_signal 0 && klish_active="yes"
    echo "klish_enable=\"$klish_enable\""
    echo "klish_usable=\"$klish_usable\""
    echo "klish_active=\"$klish_active\""

%start -u @l_susr@
    rcService klish enable yes || exit 0
    rcService klish active yes && exit 0
    @l_prefix@/bin/konfd -s $klish_socket -p $klish_pidfile -u @l_rusr@ -g @l_rgrp@

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

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

