#!/bin/bash
#
# Startup script for pptpd
#
# chkconfig: 3456 85 15
# description: PPTP server
# processname: pptpd
# pidfile: /var/run/pptpd.pid
# config: /etc/pptpd.conf

### BEGIN INIT INFO
# Provides: pptpd
# Required-Start: $network
# Default-Start: 3 5
# Default-Stop: 0 1 6
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# See how we were called.
case "$1" in
  start)
        gprintf "Starting pptpd: "
        if [ -f /var/lock/subsys/pptpd ] ; then
                echo
                exit 1
        fi
        daemon /usr/sbin/pptpd
        echo
        touch /var/lock/subsys/pptpd
        ;;
  stop)
        gprintf "Shutting down pptpd: "
        killproc pptpd
        echo
        rm -f /var/lock/subsys/pptpd
        ;;
  status)
        status pptpd
        ;;
  condrestart)
	if [ -f /var/lock/subsys/pptpd ]; then
		$0 stop
		$0 start
	fi
	;;
  reload|restart)
        $0 stop
        $0 start
        gprintf "Warning: a pptpd restart does not terminate existing \n"
        gprintf "connections, so new connections may be assigned the same IP \n"
        gprintf "address and cause unexpected results.  Use restart-kill to \n"
        gprintf "destroy existing connections during a restart.\n"
        ;;
  restart-kill)
        $0 stop
        ps -ef | grep pptpd | grep -v grep | grep -v rc.d | awk '{print $2}' | uniq | xargs kill 1> /dev/null 2>&1
        $0 start
        ;;
  *)
        gprintf "Usage: %s {start|stop|restart|restart-kill|status}\n" "$0"
        exit 1
esac

exit 0
