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

%config
    taskboard_enable="$openpkg_rc_def"
    taskboard_cron="yes"
    taskboard_log_rotsteps="10"
    taskboard_log_rotminsize="10M"
    taskboard_log_rotcomplevel="9"
    taskboard_log_rotprolog="true"
    taskboard_log_rotepilog="true"

%common
    taskboard_apache_cfgfile="@l_prefix@/etc/taskboard/taskboard-apache.conf"
    taskboard_apache_pidfile="@l_prefix@/var/taskboard/run/taskboard-apache.pid"
    taskboard_apache_logfile="@l_prefix@/var/taskboard/log/taskboard-access.log"

%status -u @l_susr@ -o
    taskboard_usable="no"
    taskboard_active="no"
    @l_prefix@/sbin/apache -t -f $taskboard_apache_cfgfile 2>/dev/null && \
        taskboard_usable="yes"
    [ -f $taskboard_apache_pidfile ] && \
        kill -0 `cat $taskboard_apache_pidfile` && \
        taskboard_active="yes"
    echo "taskboard_enable=\"$taskboard_enable\""
    echo "taskboard_usable=\"$taskboard_usable\""
    echo "taskboard_active=\"$taskboard_active\""

%start -u @l_susr@
    rcService taskboard enable yes || exit 0
    rcService taskboard active yes && exit 0
    @l_prefix@/sbin/apache -f $taskboard_apache_cfgfile

%stop -u @l_susr@
    rcService taskboard enable yes || exit 0
    rcService taskboard active no  && exit 0
    [ -f $taskboard_apache_pidfile ] && \
        kill -TERM `cat $taskboard_apache_pidfile`
    sleep 2

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

%reload -u @l_susr@
    rcService taskboard enable yes || exit 0
    rcService taskboard active no  && exit 0
    @l_prefix@/sbin/apache -f $taskboard_apache_cfgfile -k graceful

%quarterly -u @l_rusr@
    rcService taskboard enable yes || exit 0
    rcService taskboard active no  && exit 0
    if [ ".$taskboard_cron" = .yes ]; then
        @l_prefix@/sbin/taskboard-cron
    fi

%daily -u @l_susr@
    rcService taskboard enable yes || exit 0
    shtool rotate -f \
        -n $taskboard_log_rotsteps -s $taskboard_log_rotminsize -d \
        -z $taskboard_log_rotcomplevel -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "$taskboard_log_rotprolog" \
        -E "$taskboard_log_rotepilog; rc taskboard reload" \
        $taskboard_apache_logfile

