#!/bin/sh
#
# Version: 0.1
#
# chkconfig: 345 99 02
# description: DiCE is an IP address update tool of DDNS. 
# processname: /usr/local/bin/DiCE/diced
#
# chmod 755 /etc/rc.d/init.d/DiCE
# chkconfig --add DiCE
# chkconfig DiCE on
# service DiCE start

script=/etc/rc.d/init.d/DiCE
diced=/usr/local/bin/DiCE/diced
prog=DiCE
lockfile=/var/lock/diced
RETVAL=0

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

[ -f $diced ] || exit 0

start(){
	echo -n $"Starting $prog: "
	$diced -d -l 2>&1 > /dev/null
	RETVAL=$?
	[ $RETVAL -eq 0 ] && success $"$base startup" || failure $"$base startup"
	echo
	[ $RETVAL -eq 0 ] && touch $lockfile
	return $RETVAL
}

stop(){
	echo -n $"Stopping $prog: "
	/usr/bin/killall $diced 2>&1 > /dev/null
	RETVAL=$?
	if [ $RETVAL -eq 0 ]
    then
            echo_success
    else
    		rm -f $lockfile
            echo_failure
    fi
    echo
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
  		stop
        ;;
  restart)
        stop
        start
        ;;
   *)
        echo "Usage: $script {start|stop|restart}"
        exit 1
esac

exit 0
