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 # Check if the service is already running?
53 msg_already_running "OpenVPN"
57 msg_starting "OpenVPN"; started
58 for tun in $TUNNELS; do
59 config="/etc/openvpn/$tun.conf"
60 if [ ! -f "$config" ]; then
61 nls "Invalid tunnel \`%s': missing config: %s" $tun "$config"
65 show "Starting OpenVPN tunnel %s" "$tun"
71 daemon --pidfile /var/run/openvpn/$tun.pid /usr/sbin/openvpn --daemon --writepid /var/run/openvpn/$tun.pid \
72 --config $config --cd /etc/openvpn ${OPENVPN_OPT}
75 [ $RETVAL -eq 0 ] && RETVAL=$RET
77 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/openvpn
82 msg_not_running "OpenVPN"
87 msg_stopping "OpenVPN"; started
88 for tun in $TUNNELS; do
89 pidfile=/var/run/openvpn/$tun.pid
90 [ -f "$pidfile" ] || continue
92 show "Stopping OpenVPN tunnel %s" "$tun"; busy
93 killproc --pidfile openvpn/$tun.pid || err=1
95 rm -f /var/lock/subsys/openvpn >/dev/null 2>&1
100 msg_not_running "OpenVPN"
105 msg_reloading "OpenVPN"; started
106 for tun in $TUNNELS; do
107 show "Reloading OpenVPN tunnel %s" "$tun"
108 killproc --pidfile openvpn/$tun.pid openvpn -HUP
109 [ $? -ne 0 -a $RETVAL -eq 0 ] && RETVAL=7
114 nls "Configured tunnels:"
116 nls "Currently active tunnels:"
117 for pidfile in /var/run/openvpn/*.pid; do
118 [ -f "$pidfile" ] || continue
119 tun=${pidfile#/var/run/openvpn/}
121 tunlup $tun && echo -n " $tun($(cat $pidfile))"
124 nm_ovpn_pid=$(ps -o pid= -C nm-openvpn-service | xargs)
125 if [ "$nm_ovpn_pid" ]; then
126 nls "NM ($nm_ovpn_pid) managed OpenVPN sessions"
127 ps -o pid,user,command --ppid=$nm_ovpn_pid
134 # See how we were called.
154 msg_usage "$0 {start|stop|restart|reload|force-reload|status}"