#!/bin/sh
#
# description: Starts and stops the AICCU daemon
#
# aiccu: Starts and stops the AICCU daemon
# description: hearbeat daemon for IPv6-in-IPv4 (Proto-41, AYIYA, Heartbeat) tunnels
# pidfile: /var/run/aiccu.pid
# config:  /etc/aiccu.conf
# chkconfig: - 59 73
# processname: aiccu
#
### BEGIN INIT INFO
# Provides: aiccu
# Required-Start: $local_fs $remote_fs $network $time $named
# Required-Stop: $local_fs $remote_fs $network $time $named
# Default-Start:
# Default-Stop:
# Short-Description: hearbeat daemon for IPv6-in-IPv4 (Proto-41, AYIYA, Heartbeat) tunnels
# Description:  aiccu automatically gives one IPv6 connectivity
#   without having to manually configure interfaces etc.
#   One does need a SixXS account and at least a tunnel. These
#   can be freely & gratis requested from the SixXS website.
#   For more information about SixXS check http://www.sixxs.net
### END INIT INFO

. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Default options
OPTIONS=

if [ -f /etc/sysconfig/aiccu ]; then
   . /etc/sysconfig/aiccu
fi

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

# Check that aiccu.conf exists.
[ -f /etc/aiccu.conf ] || exit 0

# Verify that the configuration is correct
if [ `grep -c "^username" /etc/aiccu.conf 2>/dev/null` -ne 1 ]; then
	echo "AICCU is not configured, edit /etc/aiccu.conf first"
	exit 0;
fi

RETVAL=0

start() {
    start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- aiccu start /etc/aiccu.conf
	RETVAL=$?
	return $RETVAL
}	

stop() {
    stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- aiccu
	RETVAL=$?
	return $RETVAL
}	

restart() {
	stop
	start
}	


reload () {
    msg_reloading aiccu
    stop_daemon --pidfile "$PIDFILE" --expect-user root -HUP -- aiccu
    RETVAL=$?
    return $RETVAL
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    reload)
        reload
        ;;
    restart)
        restart
        ;;
    condstop)
        if [ -e "$LOCKFILE" ]; then
            stop
        fi
        ;;
    condrestart)
        if [ -e "$LOCKFILE" ]; then
            restart
        fi
        ;;
    condreload)
        if [ -e "$LOCKFILE" ]; then
            reload
        fi
        ;;
    status)
        status --pidfile "$PIDFILE" --expect-user root -- aiccu
        RETVAL=$?
        ;;
    *)
        msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
        RETVAL=1
esac

exit $RETVAL

