3 # OpenVPN start/stop script
4 # Adapted to Gentoo by James Yonan
6 # Originally Contributed to the OpenVPN project by
7 # Douglas Keller <doug@voidstar.dyndns.org>
10 # This script does the following:
12 # - Starts an openvpn process for each .conf file it finds in
15 # - If /etc/openvpn/xxx.sh exists for a xxx.conf file then it executes
16 # it before starting openvpn (useful for doing openvpn --mktun...).
18 # - In addition to start/stop you can do:
20 # service openvpn reload - SIGHUP
21 # service openvpn reopen - SIGUSR1
22 # service openvpn status - SIGUSR2
24 # Location of openvpn binary
25 openvpn=/usr/local/sbin/openvpn
28 piddir=/var/run/openvpn
30 # Our working directory (.conf files should be here)
34 opts="start stop restart condrestart"
42 ebegin "Starting OpenVPN"
44 # Load the TUN/TAP module
45 /sbin/modprobe tun >/dev/null 2>&1
47 if [ ! -d $piddir ]; then
53 # Start every .conf in $work and run .sh if exists
57 for c in `/bin/ls *.conf 2>/dev/null`; do
59 if [ -f "$bn.sh" ]; then
63 $openvpn --daemon openvpn-$bn --writepid $piddir/$bn.pid --config $c --cd $work
71 # Decide status based on errors/successes.
72 # If at least one tunnel succeeded, we return success.
73 # If some tunnels succeeded and some failed, we return
74 # success but give a warning.
75 if [ $successes = 1 ]; then
76 if [ $errors = 1 ]; then
77 ewarn "Note: At least one OpenVPN tunnel failed to start"
81 if [ $errors = 0 ]; then
82 ewarn "Note: No OpenVPN configuration files were found in $work"
85 eend $retstatus "Error starting OpenVPN"
89 ebegin "Stopping OpenVPN"
90 for pidf in `/bin/ls $piddir/*.pid 2>/dev/null`; do
92 kill `cat $pidf` >/dev/null 2>&1
99 # this should really be in runscript.sh
101 if [ -L "${svcdir}/started/${myservice}" ]; then
108 # attempt to restart ONLY if we are already started