3 # openvpn Start/stop the VPN daemon.
5 # chkconfig: 2345 80 20
7 # description: OpenVPN is a robust and highly configurable VPN (Virtual
8 # Private Network) daemon
11 # Source function library
12 . /etc/rc.d/init.d/functions
15 [ -f /etc/sysconfig/openvpn ] && . /etc/sysconfig/openvpn
17 # See how we were called.
20 # Check if the service is already running?
21 if [ ! -f /var/lock/subsys/openvpn ]; then
22 msg_starting "OpenVPN" ; started
23 if [ -z "$TUNNELS" ] ; then
24 nls "No tunnels configured in /etc/sysconfig/openvpn" ""
28 for tun in $TUNNELS ; do
29 show "Starting OpenVPN tunnel %s" "$tun"
30 daemon openvpn --daemon --writepid "/var/run/openvpn/$tun.pid" \
31 --config "/etc/openvpn/$tun.conf" --cd /etc/openvpn
33 [ $RETVAL -eq 0 ] || ANYRETVAL=$RETVAL
35 [ $ANYRETVAL -eq 0 ] && touch /var/lock/subsys/openvpn
37 msg_Already_Running "OpenVPN"
43 if [ -f /var/lock/subsys/openvpn ]; then
44 msg_stopping "OpenVPN"; started
45 for pidfile in /var/run/openvpn/*.pid ; do
46 [ -f "$pidfile" ] || continue
48 tun=`basename "$pidfile" | sed -e 's/\.pid$//'`
49 show "Stopping OpenVPN tunnel %s" "$tun" ; busy
50 if ! ps h $pid >/dev/null 2>&1 ; then
54 kill -TERM $pid >/dev/null 2>&1
56 if ps h $pid >/dev/null 2>&1 ; then
58 if ps h $pid >/dev/null 2>&1 ; then
60 if ps h $pid >/dev/null 2>&1 ; then
61 kill -KILL $pid >/dev/null 2>&1
67 rm -f /var/lock/subsys/openvpn >/dev/null 2>&1
69 msg_Not_Running "OpenVPN"
78 for pid in /var/run/openvpn/*.pid ; do
88 msg_Usage: "$0 {start|stop|status|restart|reload}"