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

%config
    ez_ipupdate_enable="$openpkg_rc_def"
    ez_ipupdate_mode="daemon"
    ez_ipupdate_interface=""
    ez_ipupdate_log_prolog="true"
    ez_ipupdate_log_epilog="true"
    ez_ipupdate_log_numfiles="10"
    ez_ipupdate_log_minsize="1M"
    ez_ipupdate_log_complevel="9"

%common
    ez_ipupdate_cfgfile="@l_prefix@/etc/ez-ipupdate/ez-ipupdate.conf"
    ez_ipupdate_cache="@l_prefix@/var/ez-ipupdate/cache"
    ez_ipupdate_pidfile="@l_prefix@/var/ez-ipupdate/pid"
    ez_ipupdate_signal () {
        [ -f $ez_ipupdate_pidfile ] && kill -$1 `cat $ez_ipupdate_pidfile`
    }
    ez_ipupdate_once () {
        daemon=""
        if [ ".$ez_ipupdate_mode" = .daemon -a ".$ez_ipupdate_interface" != . ]; then
            daemon="--daemon --pid-file $ez_ipupdate_pidfile --interface $ez_ipupdate_interface"
        fi
        @l_prefix@/sbin/ez-ipupdate \
            --config-file $ez_ipupdate_cfgfile \
            --cache-file $ez_ipupdate_cache \
            $daemon >/dev/null 2>&1 || true
    }

%status -o
    ez_ipupdate_usable="unknown"
    case "$ez_ipupdate_mode" in
        once | \
        quarterly | hourly | daily | weekly | monthly ) ez_ipupdate_usable="yes" ;;
        daemon ) [ ".$ez_ipupdate_interface" != . ] && ez_ipupdate_usable="yes" ;;
    esac
    ez_ipupdate_active="no"
    rcService ez-ipupdate enable yes && \
    [ ".$ez_ipupdate_mode" = ".daemon" ] && \
        ez_ipupdate_signal 0 && ez_ipupdate_active="yes"
    echo "ez_ipupdate_enable=\"$ez_ipupdate_enable\""
    echo "ez_ipupdate_usable=\"$ez_ipupdate_usable\""
    echo "ez_ipupdate_active=\"$ez_ipupdate_active\""

%start
    rcService ez-ipupdate enable yes || exit 0
    rcService ez-ipupdate active yes && exit 0
    case "$ez_ipupdate_mode" in
        once | \
        daemon | \
        quarterly | hourly | daily | weekly | monthly )
            ez_ipupdate_once
            ;;
    esac

%stop
    rcService ez-ipupdate enable yes || exit 0
    rcService ez-ipupdate active no  && exit 0
    ez_ipupdate_signal TERM
    sleep 2
    rm -f $ez_ipupdate_pidfile 2>/dev/null || true

%restart
    rcService ez-ipupdate enable yes || exit 0
    rcService ez-ipupdate active no  && exit 0
    rc ez-ipupdate stop start

%quarterly
    rcService ez-ipupdate enable yes || exit 0
    [ ".$ez_ipupdate_mode" = .quarterly ] && ez_ipupdate_once
    exit 0

%hourly
    rcService ez-ipupdate enable yes || exit 0
    [ ".$ez_ipupdate_mode" = .hourly ] && ez_ipupdate_once
    exit 0

%daily
    rcService ez-ipupdate enable yes || exit 0
    [ ".$ez_ipupdate_mode" = .daily ] && ez_ipupdate_once
    exit 0

%weekly
    rcService ez-ipupdate enable yes || exit 0
    [ ".$ez_ipupdate_mode" = .weekly ] && ez_ipupdate_once
    exit 0

%monthly
    rcService ez-ipupdate enable yes || exit 0
    [ ".$ez_ipupdate_mode" = .monthly ] && ez_ipupdate_once
    exit 0

