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

%config
    dhcp_agent_enable="$openpkg_rc_def"
    dhcp_agent_interface=""
    dhcp_agent_log_prolog="true"
    dhcp_agent_log_epilog="true"
    dhcp_agent_log_numfiles="10"
    dhcp_agent_log_minsize="1M"
    dhcp_agent_log_complevel="9"

%common
    dhcp_agent_pidfile="@l_prefix@/var/dhcp-agent/dhcp-client/$dhcp_agent_interface.pid"
    dhcp_agent_signal () {
        [ -f $dhcp_agent_pidfile ] && kill -$1 `cat $dhcp_agent_pidfile`
    }

%status -u @l_susr@ -o
    dhcp_agent_usable="no"
    dhcp_agent_active="no"
    rcService dhcp-agent enable yes && \
        [ ".$dhcp_agent_interface" != . ] && dhcp_agent_usable="yes"
    rcService dhcp-agent enable yes && \
        rcVarIsYes dhcp_agent_usable && \
        dhcp_agent_signal 0 && dhcp_agent_active="yes"
    echo "dhcp_agent_enable=\"$dhcp_agent_enable\""
    echo "dhcp_agent_usable=\"$dhcp_agent_usable\""
    echo "dhcp_agent_active=\"$dhcp_agent_active\""

%start -p 50 -u @l_susr@
    rcService dhcp-agent enable yes || exit 0
    rcService dhcp-agent active yes && exit 0
    rcService dhcp-agent usable && \
    @l_prefix@/sbin/dhcp-client 2>/dev/null -i $dhcp_agent_interface

%stop -p 950 -u @l_susr@
    rcService dhcp-agent enable yes || exit 0
    rcService dhcp-agent active no && exit 0
    rcService dhcp-agent usable && \
    @l_prefix@/sbin/dhcp-client 2>/dev/null -k -i $dhcp_agent_interface

%restart -u @l_susr@
    rcService dhcp-agent enable yes || exit 0
    rcService dhcp-agent active no && exit 0
    rc dhcp_agent stop
    sleep 2
    rc dhcp_agent start

%reload -u @l_susr@
    rcService dhcp-agent enable yes || exit 0
    rcService dhcp-agent usable && \
    @l_prefix@/sbin/dhcp-client 2>/dev/null -c -i $dhcp_agent_interface

%daily -u @l_susr@
    rcService dhcp-agent enable yes || exit 0
    shtool rotate -f \
        -n ${dhcp_agent_log_numfiles} -s ${dhcp_agent_log_minsize} -d \
        -z ${dhcp_agent_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "${dhcp_agent_log_prolog}" \
        -E "${dhcp_agent_log_epilog}" \
        @l_prefix@/var/dhcp-agent/dhcp-agent.log

