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

%config
    hadoop_enable="$openpkg_rc_def"
    hadoop_flags="-server -Xms256M -Xmx512M"
    hadoop_log_prolog="true"
    hadoop_log_epilog="true"
    hadoop_log_numfiles="10"
    hadoop_log_minsize="1M"
    hadoop_log_complevel="9"

%common
    hadoop_pidfile="@l_prefix@/var/hadoop/run/hadoop.pid"
    hadoop_logfile="@l_prefix@/var/hadoop/log/hadoop.log"
    hadoop_signal () {
        [ -f $hadoop_pidfile ] && kill -$1 `cat $hadoop_pidfile`
    }

%status -u @l_rusr@ -o
    hadoop_usable="unknown"
    hadoop_active="no"
    rcService hadoop enable yes && \
        hadoop_signal 0 && hadoop_active="yes"
    echo "hadoop_enable=\"$hadoop_enable\""
    echo "hadoop_usable=\"$hadoop_usable\""
    echo "hadoop_active=\"$hadoop_active\""

%start -u @l_rusr@
    rcService hadoop enable yes || exit 0
    rcService hadoop active yes && exit 0
    #   FIXME

%stop -u @l_rusr@
    rcService hadoop enable yes || exit 0
    rcService hadoop active no && exit 0
    hadoop_signal TERM
    sleep 2
    rm -f $hadoop_pidfile 2>/dev/null || true

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

%daily -u @l_rusr@
    rcService hadoop enable yes || exit 0
    shtool rotate -f \
        -n $hadoop_log_numfiles -s $hadoop_log_minsize -d \
        -z $hadoop_log_complevel -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "$hadoop_log_prolog" \
        -E "$hadoop_log_epilog; rc hadoop restart" \
        $hadoop_logfile

