#!/bin/sh
#
# vpnd       	Start the vpn daemon.
#
#               This is a script suitable for the Debian Linux distribution.
#               Copy it to /etc/init.d/vpnd, make it executable, and
#               execute "update-rc.d vpnd defaults 51".
#

VPND=/usr/sbin/vpnd
DESC="Virtual Private Network Daemon"
NAME=vpnd

test -f $VPND || exit 0

case "$1" in
  start)
	if [ ! -f /etc/vpnd/vpnd.key ]
	then
		echo "The vpnd key is missing." 
		echo "If vpnd is configured as a client, you need to copy the server key into /etc/vpnd. Then lauch \"/etc/init.d/vpnd start\" again"
		echo "If vpnd is configured as a server, you have probably deleted it, use \"vpnd -m\" to generate a new one"
		exit 0
	fi
	echo -n "Starting $DESC: "
		start-stop-daemon --start --quiet \
                        --exec $VPND
	echo "vpnd."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet \
                        --exec $VPND
	echo  "vpnd."
	;;
  reload|force-reload)
        echo "Reloading $DESC configuration files."
	start-stop-daemon --stop --signal 1 --quiet --pidfile \
                /var/run/$NAME.pid --exec $VPND
	;;
  restart)
	sh /etc/init.d/vpnd stop quiet
        sleep 3
        /etc/init.d/vpnd start
        ;;
  *)
	echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart}"
        exit 1
esac

exit 0
