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

%config
    cvs_enable="$openpkg_rc_def"
    cvs_daemon="no"
    cvs_daemon_gflags=""
    cvs_daemon_lflags=""
    cvs_daemon_listen="127.0.0.1:2401"
    cvs_log_prolog="true"
    cvs_log_epilog="true"
    cvs_log_numfiles="10"
    cvs_log_minsize="1M"
    cvs_log_complevel="9"

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

%status -u @l_susr@ -o
    cvs_usable="unknown"
    cvs_active="no"
    rcService cvs enable yes && rcVarIsYes cvs_daemon && \
        cvs_daemon_signal 0 && cvs_active="yes"
    echo "cvs_enable=\"$cvs_enable\""
    echo "cvs_usable=\"$cvs_usable\""
    echo "cvs_active=\"$cvs_active\""

%start -u @l_susr@
    rcService cvs enable yes || exit 0
    rcService cvs active yes && exit 0
    if rcVarIsYes cvs_daemon; then
        @l_prefix@/bin/cvs --version | grep RSE >/dev/null || exit 0
        @l_prefix@/bin/cvs -f $cvs_daemon_gflags \
            pserverd -d -p $cvs_daemon_pidfile \
            -l $cvs_daemon_listen $cvs_daemon_lflags
    fi

%stop -u @l_susr@
    rcService cvs enable yes || exit 0
    rcService cvs active no  && exit 0
    if rcVarIsYes cvs_daemon; then
        @l_prefix@/bin/cvs --version | grep RSE >/dev/null || exit 0
        cvs_daemon_signal TERM
        rm -f $cvs_daemon_pidfile 2>/dev/null || true
    fi

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

%daily -u @l_susr@
    rcService cvs enable yes || exit 0
    shtool rotate -f \
        -n ${cvs_log_numfiles} -s ${cvs_log_minsize} -d \
        -z ${cvs_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${cvs_log_prolog}" \
        -E "${cvs_log_epilog}" \
        @l_prefix@/var/cvs/cvs.log

