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

%config
    glusterfs_enable="$openpkg_rc_def"
    glusterfs_flags=""
    glusterfs_log_prolog="true"
    glusterfs_log_epilog="true"
    glusterfs_log_numfiles="10"
    glusterfs_log_minsize="1M"
    glusterfs_log_complevel="9"

%common
    glusterfs_pidfile="@l_prefix@/var/glusterfs/run/glusterfs.pid"
    glusterfs_logfile="@l_prefix@/var/glusterfs/log/glusterfs.log"
    glusterfs_signal () {
        [ -f $glusterfs_pidfile ] && kill -$1 `cat $glusterfs_pidfile`
    }

%status -u @l_rusr@ -o
    glusterfs_usable="unknown"
    glusterfs_active="no"
    rcService glusterfs enable yes && \
        glusterfs_signal 0 && glusterfs_active="yes"
    echo "glusterfs_enable=\"$glusterfs_enable\""
    echo "glusterfs_usable=\"$glusterfs_usable\""
    echo "glusterfs_active=\"$glusterfs_active\""

%start -u @l_rusr@
    rcService glusterfs enable yes || exit 0
    rcService glusterfs active yes && exit 0

%stop -u @l_rusr@
    rcService glusterfs enable yes || exit 0
    rcService glusterfs active no  && exit 0
    glusterfs_signal TERM
    sleep 2
    rm -f $glusterfs_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_rusr@
    rcService glusterfs enable yes || exit 0
    shtool rotate -f \
        -n ${glusterfs_log_numfiles} -s ${glusterfs_log_minsize} -d \
        -z ${glusterfs_log_complevel} -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "${glusterfs_log_prolog}" \
        -E "${glusterfs_log_epilog}; rc glusterfs restart" \
        $glusterfs_logfile

