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

%config
    sugarcrm_enable="$openpkg_rc_def"
    sugarcrm_cron="yes"
    sugarcrm_log_rotsteps="10"
    sugarcrm_log_rotminsize="10M"
    sugarcrm_log_rotcomplevel="9"
    sugarcrm_log_rotprolog="true"
    sugarcrm_log_rotepilog="true"

%common
    sugarcrm_apache_cfgfile="@l_prefix@/etc/sugarcrm/sugarcrm-apache.conf"
    sugarcrm_apache_pidfile="@l_prefix@/var/sugarcrm/run/sugarcrm-apache.pid"
    sugarcrm_apache_logfile="@l_prefix@/var/sugarcrm/log/sugarcrm-access.log"

%status -u @l_susr@ -o
    sugarcrm_usable="no"
    sugarcrm_active="no"
    @l_prefix@/sbin/apache -t -f $sugarcrm_apache_cfgfile 2>/dev/null && \
        sugarcrm_usable="yes"
    [ -f $sugarcrm_apache_pidfile ] && \
        kill -0 `cat $sugarcrm_apache_pidfile` && \
        sugarcrm_active="yes"
    echo "sugarcrm_enable=\"$sugarcrm_enable\""
    echo "sugarcrm_usable=\"$sugarcrm_usable\""
    echo "sugarcrm_active=\"$sugarcrm_active\""

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

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

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

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

%daily -u @l_susr@
    rcService sugarcrm enable yes || exit 0
    shtool rotate -f \
        -n $sugarcrm_log_rotsteps -s $sugarcrm_log_rotminsize -d \
        -z $sugarcrm_log_rotcomplevel -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "$sugarcrm_log_rotprolog" \
        -E "$sugarcrm_log_rotepilog; rc sugarcrm reload" \
        $sugarcrm_apache_logfile

