Files
bsdports/net/openvpn-devel/files/openvpn.sh.in.old
2024-03-08 08:21:10 +02:00

92 lines
2.4 KiB
Bash

#!/bin/sh
#
# PROVIDE: openvpn
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# This script supports running multiple instances of openvpn.
# To run additional instance link this script to something like
# % ln -s openvpn openvpn_foo
# and define additional openvpn_foo_* variables in one of
# /etc/rc.conf, /etc/rc.conf.local or /etc/rc.conf.d/openvpn_foo
#
# Below NAME should be substituted with the name of this script. By default
# it is openvpn, so read as openvpn_enable. If you linked the script to
# openvpn_foo, then read as openvpn_foo_enable etc.
#
# The following variables are supported (defaults are shown).
# You can place them in any of
# /etc/rc.conf, /etc/rc.conf.local or /etc/rc.conf.d/NAME
#
# NAME_enable="NO" # set to YES to enable openvpn
# NAME_if="" # driver(s) to load, set to "tun", "tap" or "tun tap"
#
# # optional:
# NAME_flags="" # additional command line arguments
# NAME_configfile="%%PREFIX%%/etc/openvpn/NAME.conf" # --config file
# NAME_dir="%%PREFIX%%/etc/openvpn" # --cd directory
#
# You also need to set NAME_configfile and NAME_dir, if the configuration
# file and directory where keys and certificates reside differ from the above
# settings.
#
# Note that we deliberately refrain from unloading drivers.
#
# For further documentation, please see openvpn(8).
#
. /etc/rc.subr
name="openvpn"
extra_commands="reload"
pidfile="/var/run/${name}.pid"
command="%%PREFIX%%/sbin/openvpn"
start_precmd="openvpn_start_precmd"
stop_postcmd="openvpn_stop_postcmd"
rcvar="${name}_enable"
openvpn_start_precmd()
{
for i in $interfaces ; do
# FreeBSD <= 5.4 does not know kldstat's -m option
# FreeBSD >= 6.0 does not add debug.* sysctl information
# in the default build - we check both to keep things simple
if ! sysctl debug.if_${i}_debug >/dev/null 2>&1 \
&& ! kldstat -m if_${i} >/dev/null 2>&1 ; then
if ! kldload if_${i} ; then
warn "Could not load $i module."
return 1
fi
fi
done
return 0
}
openvpn_stop_postcmd()
{
rm -f "$pidfile" || warn "Could not remove $pidfile."
}
load_rc_config aaaaa
: ${openvpn_enable="NO"}
: ${openvpn_flags=""}
: ${openvpn_if=""}
: ${openvpn_configfile="%%PREFIX%%/etc/openvpn/openvpn.conf"}
: ${openvpn_dir="%%PREFIX%%/etc/openvpn"}
configfile="${openvpn_configfile}"
dir="${openvpn_dir}"
interfaces="${openvpn_if}"
required_files=${configfile}
command_args="--cd ${dir} --daemon ${name} --config ${configfile} --writepid ${pidfile}"
run_rc_command "$1"
#EOF