#!/bin/sh
#
# openvpn       This shell script takes care of starting and stopping
#               openvpn on RedHat or other chkconfig-based system.
#
# chkconfig: 345 24 76
#
# description: OpenVPN is a robust and highly flexible tunneling application that
#              uses all of the encryption, authentication, and certification features
#              of the OpenSSL library to securely tunnel IP networks over a single
#              UDP port.
#

# Location of openvpn binary
openvpn="/usr/local/sbin/openvpn"

# Lockfile
lock="/var/lock/subsys/openvpn"

# Our working directory
work="/etc/openvpn"

# Check that binary exists
if ! [ -f  $openvpn ] 
then
  echo "openvpn binary not found"
  exit 0
fi

# See how we were called.
case "$1" in
  start)
      if [ ! -e /etc/.dont_start_secure ]; then
	
        date 010100002008
	echo -n $"Starting openvpn: "

        $openvpn --daemon --config $work/client.conf --cd $work

      fi     
	;;
  stop)
	echo -n $"Shutting down openvpn: "
        killall -9 openvpn
	;;
  restart)
	if [ ! -e /etc/.dont_start_secure ]; then
	    killall -9 openvpn
	    sleep 2
	    $openvpn --daemon --config $work/client.conf --cd $work
	fi    
	;;
  *)
	echo "Usage: openvpn {start|stop|restart}"
	exit 1
	;;
esac
exit 0
