3 # openvpn Start/stop the VPN daemon.
5 # chkconfig: 2345 11 89
7 # description: OpenVPN is a robust and highly configurable VPN (Virtual \
8 # Private Network) daemon
12 [ -f /etc/sysconfig/openvpn ] && . /etc/sysconfig/openvpn
14 [ -n "$2" ] && TUNNELS="$2"
16 # no tunnels. exit silently
17 if [ -z "$TUNNELS" ]; then
19 start|stop|restart|reload|force-reload)
25 # Source function library
26 . /etc/rc.d/init.d/functions
28 # Source networking configuration.
29 . /etc/sysconfig/network
31 # Check that networking is up.
32 if is_yes "${NETWORKING}"; then
33 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
34 msg_network_down OpenVPN
41 # check if the tunnel $1 is up
44 local pidfile=/var/run/openvpn/$tun.pid
45 local pid=$(cat $pidfile 2>/dev/null)
46 kill -0 $pid 2>/dev/null
50 # check if all the configured tunnels are up
53 for tun in $TUNNELS; do
54 tunlup $tun && continue
61 # Check if the service is already running?
63 msg_starting "OpenVPN"; started
64 for tun in $TUNNELS; do
65 config="/etc/openvpn/$tun.conf"
66 if [ ! -f "$config" ]; then
67 nls "Invalid tunnel \`%s': missing config: %s" $tun "$config"
71 show "Starting OpenVPN tunnel %s" "$tun"
77 daemon openvpn --daemon --writepid "/var/run/openvpn/$tun.pid" \
78 --config $config --cd /etc/openvpn
81 [ $RETVAL -eq 0 ] && RETVAL=$RET
83 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/openvpn
85 msg_already_running "OpenVPN"
92 msg_stopping "OpenVPN"; started
93 for tun in $TUNNELS; do
94 pidfile=/var/run/openvpn/$tun.pid
95 [ -f "$pidfile" ] || continue
97 show "Stopping OpenVPN tunnel %s" "$tun"; busy
98 killproc --pidfile openvpn/$tun.pid || err=1
100 rm -f /var/lock/subsys/openvpn >/dev/null 2>&1
102 msg_not_running "OpenVPN"
107 # See how we were called.
117 msg_reloading "OpenVPN"; started
118 for tun in $TUNNELS; do
119 show "Reloading OpenVPN tunnel %s" "$tun"
120 killproc --pidfile openvpn/$tun.pid openvpn -HUP
121 [ $? -ne 0 -a $RETVAL -eq 0 ] && RETVAL=7
124 msg_not_running OpenVPN
135 nls "Configured tunnels:"
137 nls "Currently active tunnels:"
138 for pidfile in /var/run/openvpn/*.pid; do
139 [ -f "$pidfile" ] || continue
140 tun=${pidfile#/var/run/openvpn/}
142 tunlup $tun && echo -n " $tun($(cat $pidfile))"
149 msg_usage "$0 {start|stop|restart|reload|force-reload|status}"