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_already_running "OpenVPN"
67 msg_starting "OpenVPN"; started
68 for tun in $TUNNELS; do
69 config="/etc/openvpn/$tun.conf"
70 if [ ! -f "$config" ]; then
71 nls "Invalid tunnel \`%s': missing config: %s" $tun "$config"
75 show "Starting OpenVPN tunnel %s" "$tun"
81 daemon --pidfile /var/run/openvpn/$tun.pid /usr/sbin/openvpn --daemon --writepid /var/run/openvpn/$tun.pid \
82 --config $config --cd /etc/openvpn ${OPENVPN_OPT}
85 [ $RETVAL -eq 0 ] && RETVAL=$RET
87 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/openvpn
92 msg_not_running "OpenVPN"
97 msg_stopping "OpenVPN"; started
98 for tun in $TUNNELS; do
99 pidfile=/var/run/openvpn/$tun.pid
100 [ -f "$pidfile" ] || continue
102 show "Stopping OpenVPN tunnel %s" "$tun"; busy
103 killproc --pidfile openvpn/$tun.pid || err=1
105 rm -f /var/lock/subsys/openvpn >/dev/null 2>&1
110 msg_not_running "OpenVPN"
115 msg_reloading "OpenVPN"; started
116 for tun in $TUNNELS; do
117 show "Reloading OpenVPN tunnel %s" "$tun"
118 killproc --pidfile openvpn/$tun.pid openvpn -HUP
119 [ $? -ne 0 -a $RETVAL -eq 0 ] && RETVAL=7
124 nls "Configured tunnels:"
126 nls "Currently active tunnels:"
127 for pidfile in /var/run/openvpn/*.pid; do
128 [ -f "$pidfile" ] || continue
129 tun=${pidfile#/var/run/openvpn/}
131 tunlup $tun && echo -n " $tun($(cat $pidfile))"
134 nm_ovpn_pid=$(ps -o pid= -C nm-openvpn-service | xargs)
135 if [ "$nm_ovpn_pid" ]; then
136 nls "NM ($nm_ovpn_pid) managed OpenVPN sessions"
137 ps -o pid,user,command --ppid=$nm_ovpn_pid
144 # See how we were called.
164 msg_usage "$0 {start|stop|restart|reload|force-reload|status}"