The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#! /bin/sh

# Place this file at /etc/init.d/dynsudp (or
# /etc/rc.d/init.d/dynsudp) and make symlinks to
#   /etc/rc.d/rc0.d/K02dynsudp
#   /etc/rc.d/rc1.d/K02dynsudp
#   /etc/rc.d/rc2.d/K02dynsudp
#   /etc/rc.d/rc3.d/S98dynsudp
#   /etc/rc.d/rc4.d/S98dynsudp
#   /etc/rc.d/rc5.d/S98dynsudp
#
# Or, if you have chkconfig, simply:
# chkconfig --add dynsudp
#
# Proper init scripts on Linux systems normally require setting lock
# and pid files under /var/run as well as reacting to network
# settings, so you should treat this with care.

PREFIX=/home/johan/projects/dynsudp
DAEMON="$PREFIX/bin/dynsudp --conf_file=$PREFIX/etc/dynsudp.conf"
PID_FILE="/tmp/dynsudp.pid"


#
# Get the status
#

if [ -f $PID_FILE ]; then
	PID=`cat $PID_FILE`
	if kill -0 $PID > /dev/null 2>&1 ; then
		STATUS="dynsudp (pid $PID) is running"
		RUNNING=1
	else
		STATUS="dynsudp (pid $PID) is not running"
		RUNNING=0
	fi
else
	STATUS="dynsudp is not running"
	RUNNING=0
fi

#
# Get the arguments
#

OP=$1
COMP=$2

STOPSIG=USR2

if [ "x$OP" = "x" ]; then
	OP="help"
fi

if [ $OP = "help" ]; then

	echo "usage: $0 [status|start|restart|stop]"

elif [ $OP = "status" ]; then

	echo $STATUS

elif [ $OP = "start" ]; then

	if [ $RUNNING -eq 0 ]; then
		if $DAEMON; then
			echo "$0 $OP: dynsudp started"
		else
			echo "$0 $OP: dynsudp could not be started"
			ERROR=1
		fi
	else
		echo "$0 $OP: dynsudp already running"
		ERROR=1
	fi
	
elif [ $OP = "restart" ]; then

	$0 stop
	$0 start

elif [ $OP = "stop" ]; then

	if [ $RUNNING -eq 0 ]; then
		echo "$0 $OP: dynsudp not running"
	elif kill -$STOPSIG $PID ; then
		echo "$0 $OP: dynsudp stopped"
	else
		echo "$0 $OP: dynsudp (pid $PID) could not be stopped"
	fi

fi	
		
exit 0