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

%config
    glassfish_enable="$openpkg_rc_def"
    glassfish_domains="domain1"
    glassfish_log_prolog="true"
    glassfish_log_epilog="true"
    glassfish_log_numfiles="10"
    glassfish_log_minsize="1M"
    glassfish_log_complevel="9"

%common
    glassfish_logfile="@l_prefix@/var/glassfish/log/glassfish.log"
    glassfish_signal () {
        test ".`@l_prefix@/bin/asadmin list-domains 2>&1 | grep 'domain1 running'`" != .
    }

%status -u @l_rusr@ -o
    glassfish_usable="unknown"
    glassfish_active="no"
    rcService glassfish enable yes && \
        glassfish_signal 0 && glassfish_active="yes"
    echo "glassfish_enable=\"$glassfish_enable\""
    echo "glassfish_usable=\"$glassfish_usable\""
    echo "glassfish_active=\"$glassfish_active\""

%start -u @l_rusr@
    rcService glassfish enable yes || exit 0
    rcService glassfish active yes && exit 0
    for domain in $glassfish_domains; do
        ( eval "nohup @l_prefix@/bin/asadmin start-domain $domain </dev/null >>$glassfish_logfile 2>&1 &"
        ) >/dev/null 2>&1 || true
    done

%stop -u @l_rusr@
    rcService glassfish enable yes || exit 0
    rcService glassfish active no  && exit 0
    for domain in $glassfish_domains; do
        ( eval "nohup @l_prefix@/bin/asadmin stop-domain $domain </dev/null >>$glassfish_logfile 2>&1 &"
        ) >/dev/null 2>&1 || true
    done

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

%daily -u @l_susr@
    rcService glassfish enable yes || exit 0
    shtool rotate -f \
        -n ${glassfish_log_numfiles} -s ${glassfish_log_minsize} -d \
        -z ${glassfish_log_complevel} -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "${glassfish_log_prolog}" \
        -E "${glassfish_log_epilog}; rc glassfish restart" \
        $glassfish_logfile

