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

%config
    festival_enable="$openpkg_rc_def"
    festival_daemon="no"
    festival_log_prolog="true"
    festival_log_epilog="true"
    festival_log_numfiles="10"
    festival_log_minsize="1M"
    festival_log_complevel="9"

%common
    festival_logfile="@l_prefix@/var/festival/festival.log"
    festival_pidfile="@l_prefix@/var/festival/festival.pid"
    festival_signal () {
        [ -f $festival_pidfile ] && kill -$1 `cat $festival_pidfile`
    }

%status -u @l_nusr@ -o
    festival_usable="unknown"
    festival_active="no"
    rcService festival enable yes && \
        festival_signal 0 && festival_active="yes"
    echo "festival_enable=\"$festival_enable\""
    echo "festival_usable=\"$festival_usable\""
    echo "festival_active=\"$festival_active\""

%start -u @l_nusr@
    rcService festival enable yes || exit 0
    rcService festival active yes && exit 0
    rcVarIsYes festival_daemon || exit 0
    (   nohup @l_prefix@/bin/festival --server \
        </dev/null >/dev/null 2>&1 &
        echo $! >$festival_pidfile
    ) >/dev/null 2>&1

%stop -u @l_nusr@
    rcService festival enable yes || exit 0
    rcService festival active no  && exit 0
    rcVarIsYes festival_daemon || exit 0
    festival_signal TERM
    sleep 2
    rm -f $festival_pidfile >/dev/null 2>&1 || true

%restart -u @l_nusr@
    rcService festival enable yes || exit 0
    rcService festival active no  && exit 0
    rcVarIsYes festival_daemon || exit 0
    rc festival stop start

%daily -u @l_nusr@
    rcService festival enable yes || exit 0
    rcVarIsYes festival_daemon || exit 0
    shtool rotate -f \
        -n ${festival_log_numfiles} -s ${festival_log_minsize} -d \
        -z ${festival_log_complevel} -m 664 -o @l_nusr@ -g @l_ngrp@ \
        -P "${festival_log_prolog}" \
        -E "${festival_log_epilog}; rc festival restart" \
        $festival_logfile

