#!/bin/dash
# Description: Teredo IPv6 tunneling client
# jamesbond 2015

PIDFILE=/var/run/miredo.pid 
DAEMON=miredo

start_daemon() {
	echo "Starting $DAEMON."
	$DAEMON
}

stop_daemon() {
	echo "Stopping $DAEMON."
	if [ -s $PIDFILE ]; then
		read pid < $PIDFILE
		kill $pid
		rm -f $PIDFILE
	fi
}

reload_daemon() {
	echo "Reloading $DAEMON."
	if [ -s $PIDFILE ]; then
		read pid < $PIDFILE
		kill -HUP $pid
	fi
}

is_up_daemon() {
	test -s $PIDFILE
}

case $1 in
	start)
		start_daemon
		;;
		
	stop)
		stop_daemon
		;;
		
	restart)
		stop_daemon
		sleep 1
		start_daemon
		;;
	reload)
		reload_daemon
		;;
		
	status)
		is_up_daemon && echo "$DAEMON is running." || echo "$DAEMON is stopped."
		;;		
		
esac
