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

%config
    php_fpm_enable="$openpkg_rc_def"
    php_fpm_log_prolog="true"
    php_fpm_log_epilog="true"
    php_fpm_log_numfiles="10"
    php_fpm_log_minsize="1M"
    php_fpm_log_complevel="9"

%common
    php_fpm_inifile="@l_prefix@/etc/php-fpm/php-fpm.ini"
    php_fpm_cfgfile="@l_prefix@/etc/php-fpm/php-fpm.conf"
    php_fpm_pidfile="@l_prefix@/var/php-fpm/run/php-fpm.pid"
    php_fpm_logfile="@l_prefix@/var/php-fpm/log/php-fpm.log"
    php_fpm_signal () {
        [ -f $php_fpm_pidfile ] && kill -$1 `cat $php_fpm_pidfile`
    }

%status -u @l_susr@ -o
    php_fpm_usable="unknown"
    php_fpm_active="no"
    rcService php-fpm enable yes && \
        php_fpm_signal 0 && php_fpm_active="yes"
    echo "php_fpm_enable=\"$php_fpm_enable\""
    echo "php_fpm_usable=\"$php_fpm_usable\""
    echo "php_fpm_active=\"$php_fpm_active\""

%start -u @l_susr@
    rcService php-fpm enable yes || exit 0
    rcService php-fpm active yes && exit 0
    @l_prefix@/sbin/php-fpm \
        -c "$php_fpm_inifile" \
        -y "$php_fpm_cfgfile"

%stop -u @l_susr@
    rcService php-fpm enable yes || exit 0
    rcService php-fpm active no  && exit 0
    php_fpm_signal TERM
    sleep 2
    rm -f $php_fpm_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService php-fpm enable yes || exit 0
    shtool rotate -f \
        -n ${php_fpm_log_numfiles} -s ${php_fpm_log_minsize} -d \
        -z ${php_fpm_log_complevel} -m 664 -o @l_nusr@ -g @l_ngrp@ \
        -P "${php_fpm_log_prolog}" \
        -E "${php_fpm_log_epilog}; rc php_fpm restart" \
        $php_fpm_logfile

