#!/bin/sh
#
# xl2tpd	This shell script takes care of starting and stopping l2tpd.
#
# description:	Layer 2 Tunnelling Protocol Daemon (RFC 2661)
#

# processname:	xl2tpd
CONFIG_FILE=/etc/xl2tpd/l2tpd.conf
SECRETS_FILE=/etc/xl2tpd/l2tp-secrets
DAEMON=xl2tpd

[ -x /usr/sbin/$DAEMON ] || exit 0

RETVAL=0

start() {
	echo -n "Starting $DAEMON : "
	if [ ! -d /var/run/xl2tpd ]
	then
		mkdir /var/run/xl2tpd
	fi
	/usr/sbin/$DAEMON -D -c $CONFIG_FILE -s $SECRETS_FILE &
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$DAEMON
	echo ""
	return $RETVAL
}

stop() {
	echo -n "Stopping $DAEMON "
	kill -9 `cat /var/run/xl2tpd.pid`
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$DAEMON
	return $RETVAL
}

restart() {
	stop
	start
}


status() {
	PID=`ps ax | awk '{if (match($5, ".*/xl2tpd$") || $5 == "xl2tpd") print $1}'`
        if test "$PID" != ""; then
	        echo "xl2tpd is running."
        else
	        echo "xl2tpd is not running."
	fi
}


# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status
	;;
  restart|reload)
	restart
	;;
  condrestart)
	[ -f /var/lock/subsys/$DAEMON ] && restart || :
	;;
  *)
	echo "Usage: $DAEMON {start|stop|status|restart|reload|condrestart}"
	exit 1
esac
