#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: udp-proxy-2020
# REQUIRE: DAEMON NETWORKING
#
# Add the following lines to /etc/rc.conf.local to enable UDP Proxy 2020
#
# udp_proxy_2020_enable="YES"
#

. /etc/rc.subr
. /usr/local/etc/udp-proxy-2020.conf

name=udp_proxy_2020
rcvar=udp_proxy_2020_enable
pidfile=/var/run/udp-proxy-2020.pid

extra_commands="status cleanup"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
cleanup_cmd="${name}_cleanup"
status_cmd="${name}_status"

load_rc_config ${name}
: ${udp_proxy_2020_enable:=no}


udp_proxy_2020_start() {
    /usr/sbin/daemon -cf -p ${pidfile} /usr/local/bin/udp-proxy-2020 ${udp_vars}
}

udp_proxy_2020_stop() {
    [ -f ${pidfile} ] && kill `cat ${pidfile}` || echo "Unable to kill ${name}.  Missing pid file?"
}

udp_proxy_2020_cleanup() {
    [ -f ${pidfile} ] && rm ${pidfile}
}

udp_proxy_2020_status() {
    if [ ! -f ${pidfile} ]; then
        echo "udp-proxy-2020 is not running."
    elif [ -n "$(pgrep -F ${pidfile} udp-proxy-2020)" ] ; then
        echo "udp-proxy-2020 is running ($(cat ${pidfile}))"
    else
        echo "udp-proxy-2020 is not running but left stale pidfile."
    fi
}

run_rc_command "$1"
