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

%config
    bacula_enable="$openpkg_rc_def"
    bacula_dir_enable="@with_server@"
    bacula_sd_enable="@with_server@"
    bacula_fd_enable="yes"
    bacula_debug=""
    bacula_log_files="@l_prefix@/var/bacula/log"
    bacula_log_prolog="true"
    bacula_log_epilog="true"
    bacula_log_numfiles="10"
    bacula_log_minsize="1M"
    bacula_log_complevel="9"

%status -u @l_susr@ -o
    bacula_usable="no"
    bacula_active="no"
    [ ".`@l_prefix@/libexec/bacula/bacula status 2>/dev/null | grep running`" != . ] && bacula_active="yes"
    echo "bacula_enable=\"$bacula_enable\""
    echo "bacula_usable=\"$bacula_usable\""
    echo "bacula_active=\"$bacula_active\""

%start -u @l_susr@
    rcService bacula enable yes || exit 0
    rcService bacula active yes && exit 0
    @l_prefix@/libexec/bacula/bacula start \
        "$bacula_debug" $bacula_dir_enable $bacula_sd_enable $bacula_fd_enable

%stop -u @l_susr@
    rcService bacula enable yes || exit 0
    rcService bacula active no  && exit 0
    @l_prefix@/libexec/bacula/bacula stop

%restart -u @l_susr@
    rcService bacula enable yes || exit 0
    rc bacula stop
    sleep 5
    rc bacula start

%daily -u @l_susr@
    rcService bacula enable yes || exit 0
    if [ ".$bacula_log_files" != . ]; then
        shtool rotate -f \
            -n ${bacula_log_numfiles} -s ${bacula_log_minsize} -d \
            -z ${bacula_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 640 \
            -P "${bacula_log_prolog}" \
            -E "${bacula_log_epilog}" \
            $bacula_log_files
    fi

