2013-12-22 02:21:11 +05:30
|
|
|
#!@SBINDIR@/openrc-run
|
2015-12-05 04:22:19 +05:30
|
|
|
# Copyright (c) 2007-2015 The OpenRC Authors.
|
|
|
|
# See the Authors file at the top-level directory of this distribution and
|
2021-12-21 06:37:00 +05:30
|
|
|
# https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS
|
2015-12-05 04:22:19 +05:30
|
|
|
#
|
|
|
|
# This file is part of OpenRC. It is subject to the license terms in
|
|
|
|
# the LICENSE file found in the top-level directory of this
|
2021-12-21 06:37:00 +05:30
|
|
|
# distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE
|
2015-12-05 04:22:19 +05:30
|
|
|
# This file may not be copied, modified, propagated, or distributed
|
|
|
|
# except according to the terms contained in the LICENSE file.
|
2007-11-28 19:10:15 +05:30
|
|
|
|
2008-03-20 01:27:24 +05:30
|
|
|
vpn=${RC_SVCNAME#*.}
|
2007-11-28 19:10:15 +05:30
|
|
|
name="OpenVPN"
|
2009-04-27 17:36:54 +05:30
|
|
|
[ "$vpn" != openvpn ] && name="$name ($vpn)"
|
2021-11-29 11:25:42 +05:30
|
|
|
command=/sbin/openvpn
|
2007-11-28 19:10:15 +05:30
|
|
|
|
2017-12-20 22:31:29 +05:30
|
|
|
pidfile=/var/run/"$RC_SVCNAME".pid
|
2021-11-29 11:25:42 +05:30
|
|
|
: ${openvpn_dir:=/etc/openvpn}
|
2009-04-27 17:36:54 +05:30
|
|
|
: ${openvpn_config:=$openvpn_dir/$vpn.conf}
|
|
|
|
command_args="$openvpn_args --daemon --config $openvpn_config"
|
|
|
|
command_args="$command_args --writepid $pidfile"
|
|
|
|
required_dirs=$openvpn_dir
|
|
|
|
required_files=$openvpn_config
|
2007-11-28 19:10:15 +05:30
|
|
|
|
|
|
|
# If we're an openvpn client, then supply a nice default config
|
|
|
|
# You can find sample up/down scripts in the OpenRC support/openvpn dir
|
2009-04-27 17:36:54 +05:30
|
|
|
if yesno $openvpn_client; then
|
|
|
|
: ${openvpn_up:=${openvpn_dir}/up.sh}
|
|
|
|
: ${openvpn_down:=${openvpn_dir}/down.sh}
|
|
|
|
command_args="$command_args --nobind --up-delay --up-restart --down-pre"
|
|
|
|
command_args="$command_args --up $openvpn_up"
|
|
|
|
command_args="$command_args --down $openvpn_down"
|
|
|
|
required_files="$required_files $openvpn_up $openvpn_down"
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2007-11-28 19:10:15 +05:30
|
|
|
in_background_fake="start stop"
|
2009-04-27 17:36:54 +05:30
|
|
|
start_inactive=YES
|
2007-11-28 19:10:15 +05:30
|
|
|
fi
|
|
|
|
|
2008-01-11 17:48:05 +05:30
|
|
|
depend()
|
|
|
|
{
|
2008-01-23 17:38:52 +05:30
|
|
|
need localmount net
|
2007-11-28 19:10:15 +05:30
|
|
|
use dns
|
2008-01-23 17:38:52 +05:30
|
|
|
after bootmisc
|
2007-11-28 19:10:15 +05:30
|
|
|
}
|
|
|
|
|
2008-01-11 17:48:05 +05:30
|
|
|
start_pre()
|
|
|
|
{
|
2007-11-28 19:10:15 +05:30
|
|
|
# Linux has good dynamic tun/tap creation
|
2009-04-27 17:36:54 +05:30
|
|
|
if [ "$RC_UNAME" = Linux ]; then
|
2007-11-28 19:10:15 +05:30
|
|
|
if [ ! -e /dev/net/tun ]; then
|
|
|
|
if ! modprobe tun; then
|
|
|
|
eerror "TUN/TAP support is not available in this kernel"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -h /dev/net/tun -a -c /dev/misc/net/tun ]; then
|
|
|
|
ebegin "Detected broken /dev/net/tun symlink, fixing..."
|
|
|
|
rm -f /dev/net/tun
|
|
|
|
ln -s /dev/misc/net/tun /dev/net/tun
|
|
|
|
eend $?
|
|
|
|
fi
|
2007-11-28 21:42:45 +05:30
|
|
|
else
|
2013-12-02 06:55:01 +05:30
|
|
|
if command -v kldload >/dev/null 2>&1; then
|
2008-01-11 16:25:36 +05:30
|
|
|
# Hammer the modules home by default
|
|
|
|
sysctl -a | grep -q '\.tun\.' || kldload if_tun
|
|
|
|
sysctl -a | grep -q '\.tap\.' || kldload if_tap
|
|
|
|
fi
|
2007-11-28 19:10:15 +05:30
|
|
|
fi
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2007-11-28 19:10:15 +05:30
|
|
|
# If the config file does not specify the cd option, we do
|
2009-04-27 17:36:54 +05:30
|
|
|
if ! grep -q "^[ \t]*cd[ \t].*" "$openvpn_config"; then
|
|
|
|
command_args="$command_args --cd $openvpn_dir"
|
2007-11-28 19:10:15 +05:30
|
|
|
fi
|
|
|
|
}
|