]> git.pld-linux.org Git - packages/openvpn.git/blame - openvpn.init
- added missing Requires()
[packages/openvpn.git] / openvpn.init
CommitLineData
d84d9290
JK
1#!/bin/sh
2#
3# openvpn Start/stop the VPN daemon.
4#
5# chkconfig: 2345 80 20
6#
7# description: OpenVPN is a robust and highly configurable VPN (Virtual
8# Private Network) daemon
9#
10
11# Source function library
12. /etc/rc.d/init.d/functions
13
14# Get service config
15[ -f /etc/sysconfig/openvpn ] && . /etc/sysconfig/openvpn
16
17# See how we were called.
18case "$1" in
19 start)
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" ""
25 exit 1
26 fi
27 ANYRETVAL=0
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
32 RETVAL=$?
33 [ $RETVAL -eq 0 ] || ANYRETVAL=$RETVAL
34 done
35 [ $ANYRETVAL -eq 0 ] && touch /var/lock/subsys/openvpn
36 else
37 msg_Already_Running "OpenVPN"
38 exit 1
39 fi
40 ;;
41 stop)
42 # Stop daemons.
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
47 pid=`cat "$pidfile"`
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
51 died
52 continue
53 fi
54 kill -TERM $pid >/dev/null 2>&1
55 usleep 100000
56 if ps h $pid >/dev/null 2>&1 ; then
57 sleep 1
58 if ps h $pid >/dev/null 2>&1 ; then
59 sleep 3
60 if ps h $pid >/dev/null 2>&1 ; then
61 kill -KILL $pid >/dev/null 2>&1
62 fi
63 fi
64 fi
65 ok
66 done
67 rm -f /var/lock/subsys/openvpn >/dev/null 2>&1
68 else
69 msg_Not_Running "OpenVPN"
70 exit 1
71 fi
72
73 ;;
74 status)
75 status openvpn
76 ;;
77 reload)
78 for pid in /var/run/openvpn/*.pid ; do
79 kill -HUP $pid
80 done
81 ;;
82 restart)
83 $0 stop
84 sleep 1
85 $0 start
86 ;;
87 *)
88 msg_Usage: "$0 {start|stop|status|restart|reload}"
89 exit 1
90 ;;
91esac
92
93exit $RETVAL
This page took 0.034424 seconds and 4 git commands to generate.