Fix pmacct and snort dependencies
[openwrt.git] / obsolete-buildroot / sources / openvpn
1 #!/bin/sh -e
2 #
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>
7
8 test $DEBIAN_SCRIPT_DEBUG && set -v -x
9
10 DAEMON=/usr/sbin/openvpn
11 CONFIG_DIR=/etc/openvpn
12 test -x $DAEMON || exit 0
13 test -d $CONFIG_DIR || exit 0
14
15 start_vpn () {
16 $DAEMON --daemon --writepid /var/run/openvpn.$NAME.pid \
17 --config $CONFIG_DIR/$NAME.conf --cd $CONFIG_DIR || echo -n " FAILED->"
18 echo -n " $NAME"
19 }
20 stop_vpn () {
21 kill `cat $PIDFILE` || true
22 rm $PIDFILE
23 }
24
25 case "$1" in
26 start)
27 echo -n "Starting openvpn:"
28
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 echo -n " No such VPN: $2"
40 fi
41 fi
42 echo "."
43
44 ;;
45 stop)
46 echo -n "Stopping openvpn:"
47
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 echo -n " $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 echo -n " $NAME"
62 else
63 echo -n " No such VPN: $2"
64 fi
65 fi
66 echo "."
67 ;;
68 # We only 'reload' for running VPNs. New ones will only start with 'start' or 'restart'.
69 reload|force-reload)
70 echo -n "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 echo -n "(restarted)"
80 else
81 kill -HUP `cat $PIDFILE` || true
82 # start-stop-daemon --stop --signal HUP --quiet --oknodo \
83 # --exec $DAEMON --pidfile $PIDFILE
84 echo -n " $NAME"
85 fi
86 done
87 echo "."
88 ;;
89
90 restart)
91 $0 stop $2
92 sleep 1
93 $0 start $2
94 ;;
95 *)
96 echo "Usage: $0 {start|stop|reload|restart|force-reload}" >&2
97 exit 1
98 ;;
99 esac
100
101 exit 0
102
103 # vim:set ai et sts=2 sw=2 tw=0:
This page took 0.051617 seconds and 5 git commands to generate.