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

%config
    omnisync_enable="$openpkg_rc_def"
    omnisync_flags="-M daytime/tcp -h 127.0.0.1"
    omnisync_unit="0"

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

%status -u @l_susr@ -o
    omnisync_usable="no"
    omnisync_active="no"
    rcService omnisync enable yes && \
        omnisync_signal 0 && omnisync_active="yes"
    echo "omnisync_enable=\"$omnisync_enable\""
    echo "omnisync_usable=\"$omnisync_usable\""
    echo "omnisync_active=\"$omnisync_active\""

%start -p 100 -u @l_susr@
    rcService omnisync enable yes || exit 0
    rcService omnisync active yes && exit 0
    @l_prefix@/sbin/omnisync \
        -U @l_nusr@ \
        -P $omnisync_pidfile \
        -u $omnisync_unit \
        $omnisync_flags

%stop -p 900 -u @l_susr@
    rcService omnisync enable yes || exit 0
    rcService omnisync active no  && exit 0
    omnisync_signal TERM
    sleep 2
    rm -f $omnisync_pidfile >/dev/null 2>&1 || true

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

%reload -p 100 -u @l_susr@
    rcService omnisync enable yes || exit 0
    rcService omnisync active no  && exit 0
    @l_prefix@/sbin/rndc reload

%daily -u @l_susr@
    rcService omnisync enable yes || exit 0

