package/dhcp/S80dhcp-server: allow empty INTERFACES
[buildroot-gz.git] / package / openvpn / S60openvpn
blobde82a5095e33ca73287e35c0dd1c554eb991d216
1 #!/bin/sh -e
3 # Original version by Robert Leslie
4 # <rob@mars.org>, edited by iwj and cs
5 # Modified for openvpn by Alberto Gonzalez Iniesta <agi@agi.as>
6 # Modified for restarting / starting / stopping single tunnels by Richard Mueller <mueller@teamix.net>
8 test $DEBIAN_SCRIPT_DEBUG && set -v -x
10 DAEMON=/usr/sbin/openvpn
11 CONFIG_DIR=/etc/openvpn
12 test -x $DAEMON || exit 0
13 test -d $CONFIG_DIR || exit 0
15 start_vpn () {
16 $DAEMON --daemon --writepid /var/run/openvpn.$NAME.pid \
17 --config $CONFIG_DIR/$NAME.conf --cd $CONFIG_DIR || printf " FAILED->"
18 printf " $NAME"
20 stop_vpn () {
21 kill `cat $PIDFILE` || true
22 rm $PIDFILE
25 case "$1" in
26 start)
27 printf "Starting openvpn:"
29 if test -z $2 ; then
30 for CONFIG in `cd $CONFIG_DIR; ls *.conf 2> /dev/null`; do
31 NAME=${CONFIG%%.conf}
32 start_vpn
33 done
34 else
35 if test -e $CONFIG_DIR/$2.conf ; then
36 NAME=$2
37 start_vpn
38 else
39 printf " No such VPN: $2"
42 echo "."
45 stop)
46 printf "Stopping openvpn:"
48 if test -z $2 ; then
49 for PIDFILE in `ls /var/run/openvpn.*.pid 2> /dev/null`; do
50 NAME=`echo $PIDFILE | cut -c18-`
51 NAME=${NAME%%.pid}
52 stop_vpn
53 printf " $NAME"
54 done
55 else
56 if test -e /var/run/openvpn.$2.pid ; then
57 PIDFILE=`ls /var/run/openvpn.$2.pid 2> /dev/null`
58 NAME=`echo $PIDFILE | cut -c18-`
59 NAME=${NAME%%.pid}
60 stop_vpn
61 printf " $NAME"
62 else
63 printf " No such VPN: $2"
66 echo "."
68 # We only 'reload' for running VPNs. New ones will only start with 'start' or 'restart'.
69 reload|force-reload)
70 printf "Reloading openvpn:"
71 for PIDFILE in `ls /var/run/openvpn.*.pid 2> /dev/null`; do
72 NAME=`echo $PIDFILE | cut -c18-`
73 NAME=${NAME%%.pid}
74 # If openvpn if running under a different user than root we'll need to restart
75 if egrep '^( |\t)*user' $CONFIG_DIR/$NAME.conf > /dev/null 2>&1 ; then
76 stop_vpn
77 sleep 1
78 start_vpn
79 printf "(restarted)"
80 else
81 kill -HUP `cat $PIDFILE` || true
82 # start-stop-daemon --stop --signal HUP --quiet --oknodo \
83 # --exec $DAEMON --pidfile $PIDFILE
84 printf " $NAME"
86 done
87 echo "."
90 restart)
91 $0 stop $2
92 sleep 1
93 $0 start $2
96 echo "Usage: $0 {start|stop|reload|restart|force-reload}" >&2
97 exit 1
99 esac
101 exit 0
103 # vim:set ai et sts=2 sw=2 tw=0: