wok annotate openvpn/stuff/etc/init.d/openvpn-client @ rev 17543

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