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

%config
    zope_enable="$openpkg_rc_def"
    zope_log_access_file="@l_prefix@/var/zope/log/Z2.log"
    zope_log_access_prolog="true"
    zope_log_access_epilog="true"
    zope_log_access_numfiles="10"
    zope_log_access_minsize="1M"
    zope_log_access_complevel="9"
    zope_log_event_file="@l_prefix@/var/zope/log/event.log"
    zope_log_event_prolog="true"
    zope_log_event_epilog="true"
    zope_log_event_numfiles="10"
    zope_log_event_minsize="1M"
    zope_log_event_complevel="9"

%status -u @l_rusr@ -o
    zope_usable="unknown"
    zope_active="no"
    rcService zope enable yes && \
        @l_prefix@/bin/zopectl status | grep -q "pid=" && zope_active="yes"
    echo "zope_enable=\"$zope_enable\""
    echo "zope_usable=\"$zope_usable\""
    echo "zope_active=\"$zope_active\""

%start -p 400 -u @l_rusr@
    rcService zope enable yes || exit 0
    rcService zope active yes && exit 0
    @l_prefix@/bin/zopectl start

%stop -p 600 -u @l_rusr@
    rcService zope enable yes || exit 0
    rcService zope active no  && exit 0
    @l_prefix@/bin/zopectl stop

%restart -p 400 -u @l_rusr@
    rcService zope enable yes || exit 0
    @l_prefix@/bin/zopectl restart

%reload -p 400 -u @l_rusr@
    rcService zope enable yes || exit 0
    rcService zope active no  && exit 0
    @l_prefix@/bin/zopectl logrotate

%daily -u @l_rusr@
    rcService zope enable yes || exit 0
    shtool rotate -f \
        -n ${zope_log_access_numfiles} -s ${zope_log_access_minsize} -d \
        -z ${zope_log_access_complevel} -m 600 -o @l_rusr@ -g @l_rgrp@ \
        -P "$zope_log_access_prolog" \
        -E "$zope_log_access_epilog && rc zope reload" \
        $zope_log_access_file
    shtool rotate -f \
        -n ${zope_log_event_numfiles} -s ${zope_log_event_minsize} -d \
        -z ${zope_log_event_complevel} -m 600 -o @l_rusr@ -g @l_rgrp@ \
        -P "$zope_log_event_prolog" \
        -E "$zope_log_event_epilog && rc zope reload" \
        $zope_log_event_file

