#!/bin/bash
#
# Use for Open peanuthull DDNS 3.0
#
# chkconfig: 2345 80 80
# description:  will be start phddns with system reboot 
#
# processname: phddns

# source function library
. /etc/rc.d/init.d/functions

DAEMONPID=$(ps -A | grep "phdaemon" | grep -v 'grep' | awk '{print $1}')

start()
{
	if [ ! -z $(pidof phtunnel) ]; then
		echo "phddns is already started, quit"
		exit 1
	else
		/usr/sbin/phdaemon &
	fi
}

stop()
{
	echo -n $"Stop phddns : "
	kill -9 $DAEMONPID > /dev/null 2>&1
	killall -9 phtunnel >/dev/null 2>&1
	killall -9 phddns_mini_httpd >/dev/null 2>&1
	echo "uninstall..."
}

restart()
{
	kill -9 $DAEMONPID > /dev/null 2>&1
	killall -9 phtunnel >/dev/null 2>&1
	killall -9 phddns_mini_httpd >/dev/null 2>&1

	sleep 1
	/usr/sbin/phdaemon &
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	*)
		echo $"Usage: $0 {start|stop}"
		exit 1
esac

