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 if the tunnel $1 is up
34 local pidfile=/var/run/openvpn/$tun.pid
35 local pid=$(cat $pidfile 2>/dev/null)
36 kill -0 $pid 2>/dev/null
40 # check if all the configured tunnels are up
43 for tun in $TUNNELS; do
44 tunlup $tun && continue
51 msg_starting "OpenVPN"; started
52 for tun in $TUNNELS; do
53 config="/etc/openvpn/$tun.conf"
54 if [ ! -f "$config" ]; then
55 nls "Invalid tunnel \`%s': missing config: %s" $tun "$config"
59 tunlup $tun && continue
60 show "Starting OpenVPN tunnel %s" "$tun"; busy
61 daemon --pidfile /var/run/openvpn/$tun.pid /usr/sbin/openvpn --daemon --writepid /var/run/openvpn/$tun.pid \
62 --config $config --cd /etc/openvpn ${OPENVPN_OPT}
65 [ $RETVAL -eq 0 ] && RETVAL=$RET
67 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/openvpn
71 msg_stopping "OpenVPN"; started
72 for tun in $TUNNELS; do
73 pidfile=/var/run/openvpn/$tun.pid
74 [ -f "$pidfile" ] || continue
76 show "Stopping OpenVPN tunnel %s" "$tun"; busy
77 killproc --pidfile openvpn/$tun.pid || err=1
80 rm -f /var/lock/subsys/openvpn >/dev/null 2>&1
85 msg_not_running "OpenVPN"
90 msg_reloading "OpenVPN"; started
91 for tun in $TUNNELS; do
92 show "Reloading OpenVPN tunnel %s" "$tun"
93 killproc --pidfile openvpn/$tun.pid openvpn -HUP
94 [ $? -ne 0 -a $RETVAL -eq 0 ] && RETVAL=7
99 nls "Configured tunnels:"
101 nls "Currently active tunnels:"
102 for pidfile in /var/run/openvpn/*.pid; do
103 [ -f "$pidfile" ] || continue
104 tun=${pidfile#/var/run/openvpn/}
106 tunlup $tun && echo -n " $tun($(cat $pidfile))"
109 nm_ovpn_pid=$(ps -o pid= -C nm-openvpn-service | xargs)
110 if [ "$nm_ovpn_pid" ]; then
111 nls "NM ($nm_ovpn_pid) managed OpenVPN sessions"
112 ps -o pid,user,command --ppid=$nm_ovpn_pid
119 # See how we were called.
139 msg_usage "$0 {start|stop|restart|reload|force-reload|status}"