wok view openvpn/stuff/etc/init.d/openvpn-server @ rev 16681

Create some /var/run/<dir> in /etc/init.d/<daemon> scritps
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun May 18 20:24:07 2014 +0000 (2014-05-18)
parents cc6e05d2cb9a
children 7f188676b59c
line source
1 #!/bin/sh
2 # /etc/init.d/openvpn-server: Start, stop and restart openvpn deamon on SliTaz, at boot
3 # time or with the command line.
4 #
5 # To start daemon at boot time, just put the right name in the $RUN_DAEMONS
6 # variable of /etc/rcS.conf and configure options with /etc/daemons.conf.
7 #
8 . /etc/init.d/rc.functions
9 . /etc/daemons.conf
11 NAME=OpenVPN
12 DESC="VPN daemon"
13 DAEMON=/usr/sbin/openvpn
14 OPTIONS=$OPENVPN_OPTIONS
15 PIDFILE=/var/run/openvpn-server.pid
17 checktundevice() {
18 if [ ! -e /dev/net/tun ]; then
19 if ! modprobe tun ; then
20 echo -n "TUN/TAP support is not available in this kernel"
21 return 1
22 fi
23 fi
24 if [ -h /dev/net/tun ] && [ -c /dev/misc/net/tun ]; then
25 echo -n "Detected broken /dev/net/tun symlink, fixing..."
26 rm -f /dev/net/tun
27 ln -s /dev/misc/net/tun /dev/net/tun
28 fi
29 }
31 [ -d /var/run/openvpn ] || mkdir -p /var/run/openvpn
32 case "$1" in
33 start)
34 checktundevice
36 if [ ! -e /etc/openvpn/server.conf ]; then
37 echo "Missing OpenVPN server config."
38 exit 1
39 fi
40 if active_pidfile $PIDFILE openvpn ; then
41 echo "$NAME already running."
42 exit 1
43 fi
44 echo -n "Starting $DESC: $NAME... "
45 $DAEMON $OPTIONS
46 status
47 ;;
48 stop)
49 if ! active_pidfile $PIDFILE openvpn ; then
50 echo "$NAME is not running."
51 exit 1
52 fi
53 echo -n "Stopping $DESC: $NAME... "
54 kill `cat $PIDFILE`
55 rm $PIDFILE
56 status
57 ;;
58 restart)
59 if ! active_pidfile $PIDFILE openvpn ; then
60 echo "$NAME is not running."
61 exit 1
62 fi
63 echo -n "Restarting $DESC: $NAME... "
64 kill `cat $PIDFILE`
65 rm $PIDFILE
66 sleep 2
67 $DAEMON $OPTIONS
68 status
69 ;;
70 *)
71 echo ""
72 echo -e "\033[1mUsage:\033[0m /etc/init.d/`basename $0` [start|stop|restart]"
73 echo ""
74 exit 1
75 ;;
76 esac
78 exit 0