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

%config
    roundcube_enable="$openpkg_rc_def"
    roundcube_log_rotsteps="10"
    roundcube_log_rotminsize="10M"
    roundcube_log_rotcomplevel="9"
    roundcube_log_rotprolog="true"
    roundcube_log_rotepilog="true"

%common
    roundcube_cfgfile="@l_prefix@/etc/roundcube/roundcube-apache.conf"
    roundcube_pidfile="@l_prefix@/var/roundcube/run/roundcube-apache.pid"
    roundcube_logfile="@l_prefix@/var/roundcube/log/roundcube-access.log"

%status -u @l_rusr@ -o
    roundcube_usable="no"
    roundcube_active="no"
    @l_prefix@/sbin/apache -t -f $roundcube_cfgfile 2>/dev/null && \
        roundcube_usable="yes"
    [ -f $roundcube_pidfile ] && \
        kill -0 `cat $roundcube_pidfile` && \
        roundcube_active="yes"
    echo "roundcube_enable=\"$roundcube_enable\""
    echo "roundcube_usable=\"$roundcube_usable\""
    echo "roundcube_active=\"$roundcube_active\""

%start -u @l_rusr@
    rcService roundcube enable yes || exit 0
    rcService roundcube active yes && exit 0
    @l_prefix@/sbin/apache -f $roundcube_cfgfile

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

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

%reload -u @l_rusr@
    rcService roundcube enable yes || exit 0
    rcService roundcube active no  && exit 0
    @l_prefix@/sbin/apache -f $roundcube_cfgfile -k graceful

%daily -u @l_rusr@
    rcService roundcube enable yes || exit 0
    shtool rotate -f \
        -n $roundcube_log_rotsteps -s $roundcube_log_rotminsize -d \
        -z $roundcube_log_rotcomplevel -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "$roundcube_log_rotprolog" \
        -E "$roundcube_log_rotepilog; rc roundcube reload" \
        $roundcube_logfile

