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

%config
    wordpress_enable="$openpkg_rc_def"
    wordpress_cron="yes"
    wordpress_log_rotsteps="10"
    wordpress_log_rotminsize="10M"
    wordpress_log_rotcomplevel="9"
    wordpress_log_rotprolog="true"
    wordpress_log_rotepilog="true"

%common
    wordpress_apache_cfgfile="@l_prefix@/etc/wordpress/wordpress-apache.conf"
    wordpress_apache_pidfile="@l_prefix@/var/wordpress/run/wordpress-apache.pid"
    wordpress_apache_logfile="@l_prefix@/var/wordpress/log/wordpress-access.log"

%status -u @l_susr@ -o
    wordpress_usable="no"
    wordpress_active="no"
    @l_prefix@/sbin/apache -t -f $wordpress_apache_cfgfile 2>/dev/null && \
        wordpress_usable="yes"
    [ -f $wordpress_apache_pidfile ] && \
        kill -0 `cat $wordpress_apache_pidfile` && \
        wordpress_active="yes"
    echo "wordpress_enable=\"$wordpress_enable\""
    echo "wordpress_usable=\"$wordpress_usable\""
    echo "wordpress_active=\"$wordpress_active\""

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

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

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

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

%quarterly -u @l_rusr@
    rcService wordpress enable yes || exit 0
    rcService wordpress active no  && exit 0
    if [ ".$wordpress_cron" = .yes ]; then
        @l_prefix@/sbin/wordpress-cron
    fi

%daily -u @l_susr@
    rcService wordpress enable yes || exit 0
    shtool rotate -f \
        -n $wordpress_log_rotsteps -s $wordpress_log_rotminsize -d \
        -z $wordpress_log_rotcomplevel -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "$wordpress_log_rotprolog" \
        -E "$wordpress_log_rotepilog; rc wordpress reload" \
        $wordpress_apache_logfile

