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

%config
    yourls_enable="$openpkg_rc_def"
    yourls_log_rotsteps="10"
    yourls_log_rotminsize="10M"
    yourls_log_rotcomplevel="9"
    yourls_log_rotprolog="true"
    yourls_log_rotepilog="true"

%common
    yourls_cfgfile="@l_prefix@/etc/yourls/yourls-apache.conf"
    yourls_pidfile="@l_prefix@/var/yourls/run/yourls-apache.pid"
    yourls_logfile="@l_prefix@/var/yourls/log/yourls-access.log"

%status -u @l_susr@ -o
    yourls_usable="no"
    yourls_active="no"
    @l_prefix@/sbin/apache -t -f $yourls_cfgfile 2>/dev/null && \
        yourls_usable="yes"
    [ -f $yourls_pidfile ] && \
        kill -0 `cat $yourls_pidfile` && \
        yourls_active="yes"
    echo "yourls_enable=\"$yourls_enable\""
    echo "yourls_usable=\"$yourls_usable\""
    echo "yourls_active=\"$yourls_active\""

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

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

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

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

%daily -u @l_susr@
    rcService yourls enable yes || exit 0
    shtool rotate -f \
        -n $yourls_log_rotsteps -s $yourls_log_rotminsize -d \
        -z $yourls_log_rotcomplevel -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "$yourls_log_rotprolog" \
        -E "$yourls_log_rotepilog; rc yourls reload" \
        $yourls_logfile

