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

%config
    drupal_enable="$openpkg_rc_def"
    drupal_cron="@l_drupal_cron@"
    drupal_backup="daily"

%status -u @l_susr@ -o
    drupal_usable="no"
    drupal_active="no"
    @l_prefix@/sbin/apache -t \
        -f @l_prefix@/etc/drupal/drupal-apache.conf 2>/dev/null && \
        drupal_usable="yes"
    [ -f @l_prefix@/var/drupal/run/apache.pid ] && \
        kill -0 `cat @l_prefix@/var/drupal/run/apache.pid` && \
        drupal_active="yes"
    echo "drupal_enable=\"$drupal_enable\""
    echo "drupal_usable=\"$drupal_usable\""
    echo "drupal_active=\"$drupal_active\""

%start -u @l_susr@
    rcService drupal enable yes || exit 0
    rcService drupal active yes && exit 0
    @l_prefix@/sbin/apache \
        -f @l_prefix@/etc/drupal/drupal-apache.conf

%stop -u @l_susr@
    rcService drupal enable yes || exit 0
    rcService drupal active no  && exit 0
    [ -f @l_prefix@/var/drupal/run/apache.pid ] && \
        kill -TERM `cat @l_prefix@/var/drupal/run/apache.pid`
    sleep 2

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

%quarterly -u @l_rusr@
    rcService drupal enable yes || exit 0
    if [ ".$drupal_cron" = .yes ]; then
        @l_prefix@/sbin/drupal-cron
    fi

%hourly -u @l_rusr@
    rcService drupal enable yes || exit 0
    if [ ".$drupal_backup" = .hourly ]; then
        @l_prefix@/sbin/drupal-setup backup || exit $?
    fi

%daily -u @l_rusr@
    rcService drupal enable yes || exit 0
    if [ ".$drupal_backup" = .daily ]; then
        @l_prefix@/sbin/drupal-setup backup || exit $?
    fi

%weekly -u @l_rusr@
    rcService drupal enable yes || exit 0
    if [ ".$drupal_backup" = .weekly ]; then
        @l_prefix@/sbin/drupal-setup backup || exit $?
    fi

