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

%config
    ucarp_enable="$openpkg_rc_def"
    ucarp_nic="eth0"
    ucarp_pass="fong"
    ucarp_vhid="64"
    ucarp_realip="127.0.0.1"
    ucarp_fakeip="127.0.0.2"
    ucarp_upscript="@l_prefix@/etc/ucarp/vip-up.sh"
    ucarp_dnscript="@l_prefix@/etc/ucarp/vip-down.sh"
    ucarp_log_prolog="true"
    ucarp_log_epilog="true"
    ucarp_log_numfiles="10"
    ucarp_log_minsize="1M"
    ucarp_log_complevel="9"

%common
    ucarp_pidfile="@l_prefix@/var/ucarp/ucarp.pid"
    ucarp_signal () {
        [ -f $ucarp_pidfile ] && kill -$1 `cat $ucarp_pidfile`
    }

%status -u @l_susr@ -o
    ucarp_usable="unknown"
    ucarp_active="no"
    rcService ucarp enable yes && \
        ucarp_signal 0 && ucarp_active="yes"
    echo "ucarp_enable=\"$ucarp_enable\""
    echo "ucarp_usable=\"$ucarp_usable\""
    echo "ucarp_active=\"$ucarp_active\""

%start -u @l_susr@
    rcService ucarp enable yes || exit 0
    rcService ucarp active yes && exit 0
    @l_prefix@/sbin/ucarp --interface=${ucarp_nic} \
        --pass=${ucarp_pass} --vhid=${ucarp_vhid} \
        --srcip=${ucarp_realip} --addr=${ucarp_fakeip} \
        --upscript=${ucarp_upscript} --downscript=${ucarp_dnscript} \
        >/dev/null 2>&1 &
    echo $! >$ucarp_pidfile

%stop -u @l_susr@
    rcService ucarp enable yes || exit 0
    rcService ucarp active no && exit 0
    ucarp_signal TERM
    sleep 2
    rm -f $ucarp_pidfile 2>/dev/null || true

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

%daily -u @l_susr@
    rcService ucarp enable yes || exit 0
    shtool rotate -f \
        -n ${ucarp_log_numfiles} -s ${ucarp_log_minsize} -d \
        -z ${ucarp_log_complevel} -m 644 -o @l_musr@ -g @l_mgrp@ \
        -P "${ucarp_log_prolog}" \
        -E "${ucarp_log_epilog}" \
        @l_prefix@/var/ucarp/ucarp.log

