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

%config
    cvsync_enable="$openpkg_rc_def"
    cvsync_flags=""
    cvsync_log_prolog="true"
    cvsync_log_epilog="true"
    cvsync_log_numfiles="10"
    cvsync_log_minsize="1M"
    cvsync_log_complevel="9"

%common
    cvsync_pidfile="@l_prefix@/var/cvsync/cvsync.pid"
    cvsync_logfile="@l_prefix@/var/cvsync/cvsync.log"
    cvsync_signal () {
        [ -f ${cvsync_pidfile} ] && kill -$1 `cat ${cvsync_pidfile}`
    }

%status -u @l_susr@ -o
    cvsync_usable="no"
    cvsync_active="no"
    echo "cvsync_enable=\"${cvsync_enable}\""
    echo "cvsync_usable=\"${cvsync_usable}\""
    echo "cvsync_active=\"${cvsync_active}\""

%start -u @l_susr@
    rcService cvsync enable yes || exit 0
    rcService cvsync active yes && exit 0
    @l_prefix@/bin/cvsyncd \
        -u @l_rusr@ \
        -g @l_rgrp@ \
        -p ${cvsync_pidfile} \
        -l ${cvsync_logfile} \
        ${cvsync_flags}

%stop -u @l_susr@
    rcService cvsync enable yes || exit 0
    rcService cvsync active no  && exit 0

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

%hourly -u @l_susr@
    rcService cvsync enable yes || exit 0
    @l_prefix@/bin/cvscan \
        -c @l_prefix@/etc/cvsync/cvsyncd.conf \
        >>@l_prefix@/var/cvsync/cvscan.log 2>/dev/null || true

%daily -u @l_susr@
    rcService cvsync enable yes || exit 0
    shtool rotate -f \
        -n ${cvsync_log_numfiles} -s ${cvsync_log_minsize} -d \
        -z ${cvsync_log_complevel} -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "${cvsync_log_prolog}" \
        -E "${cvsync_log_epilog}; rc cvsync restart" \
        ${cvsync_logfile}

