Debian Codegraph @

support/init.d.examples/openvpn.in

raw
1 #!@SBINDIR@/openrc-run
2 # Copyright (c) 2007-2015 The OpenRC Authors.
3 # See the Authors file at the top-level directory of this distribution and
4 # https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS
5 #
6 # This file is part of OpenRC. It is subject to the license terms in
7 # the LICENSE file found in the top-level directory of this
8 # distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE
9 # This file may not be copied, modified, propagated, or distributed
10 # except according to the terms contained in the LICENSE file.
11
12 vpn=${RC_SVCNAME#*.}
13 name="OpenVPN"
14 [ "$vpn" != openvpn ] && name="$name ($vpn)"
15 command=/sbin/openvpn
16
17 pidfile=/var/run/"$RC_SVCNAME".pid
18 : ${openvpn_dir:=/etc/openvpn}
19 : ${openvpn_config:=$openvpn_dir/$vpn.conf}
20 command_args="$openvpn_args --daemon --config $openvpn_config"
21 command_args="$command_args --writepid $pidfile"
22 required_dirs=$openvpn_dir
23 required_files=$openvpn_config
24
25 # If we're an openvpn client, then supply a nice default config
26 # You can find sample up/down scripts in the OpenRC support/openvpn dir
27 if yesno $openvpn_client; then
28 : ${openvpn_up:=${openvpn_dir}/up.sh}
29 : ${openvpn_down:=${openvpn_dir}/down.sh}
30 command_args="$command_args --nobind --up-delay --up-restart --down-pre"
31 command_args="$command_args --up $openvpn_up"
32 command_args="$command_args --down $openvpn_down"
33 required_files="$required_files $openvpn_up $openvpn_down"
34
35 in_background_fake="start stop"
36 start_inactive=YES
37 fi
38
39 depend()
40 {
41 need localmount net
42 use dns
43 after bootmisc
44 }
45
46 start_pre()
47 {
48 # Linux has good dynamic tun/tap creation
49 if [ "$RC_UNAME" = Linux ]; then
50 if [ ! -e /dev/net/tun ]; then
51 if ! modprobe tun; then
52 eerror "TUN/TAP support is not available in this kernel"
53 return 1
54 fi
55 fi
56 if [ -h /dev/net/tun -a -c /dev/misc/net/tun ]; then
57 ebegin "Detected broken /dev/net/tun symlink, fixing..."
58 rm -f /dev/net/tun
59 ln -s /dev/misc/net/tun /dev/net/tun
60 eend $?
61 fi
62 else
63 if command -v kldload >/dev/null 2>&1; then
64 # Hammer the modules home by default
65 sysctl -a | grep -q '\.tun\.' || kldload if_tun
66 sysctl -a | grep -q '\.tap\.' || kldload if_tap
67 fi
68 fi
69
70 # If the config file does not specify the cd option, we do
71 if ! grep -q "^[ \t]*cd[ \t].*" "$openvpn_config"; then
72 command_args="$command_args --cd $openvpn_dir"
73 fi
74 }