Skip to content

Commit

Permalink
openvpn: add support to start/stop single instances
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Schiller <ms@dev.tdt.de>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> (PKG_RELEASE increase)
  • Loading branch information
sch-m authored and dedeckeh committed Nov 13, 2017
1 parent 654016b commit e2f25e6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package/network/services/openvpn/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=openvpn

PKG_VERSION:=2.4.4
PKG_RELEASE:=1
PKG_RELEASE:=2

PKG_SOURCE_URL:=\
https://build.openvpn.net/downloads/releases/ \
Expand Down
53 changes: 36 additions & 17 deletions package/network/services/openvpn/files/openvpn.init
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ openvpn_add_instance() {
local dir="$2"
local conf="$3"

procd_open_instance
procd_open_instance "$name"
procd_set_param command "$PROG" \
--syslog "openvpn($name)" \
--status "/var/run/openvpn.$name.status" \
Expand Down Expand Up @@ -103,28 +103,47 @@ start_instance() {
}

start_service() {
local instance="$1"
local instance_found=0

config_cb() {
local type="$1"
local name="$2"
if [ "$type" = "openvpn" ]; then
if [ -n "$instance" -a "$instance" = "$name" ]; then
instance_found=1
fi
fi
}

. /usr/share/openvpn/openvpn.options
config_load 'openvpn'
config_foreach start_instance 'openvpn'

local path name
for path in /etc/openvpn/*.conf; do
if [ -f "$path" ]; then
name="${path##*/}"; name="${name%.conf}"
if [ -n "$instance" ]; then
[ "$instance_found" -gt 0 ] || return
start_instance "$instance"
else
config_foreach start_instance 'openvpn'

# don't start configs again that are already started by uci
if echo "$UCI_STARTED" | grep -qxF "$path"; then
continue
local path name
for path in /etc/openvpn/*.conf; do
if [ -f "$path" ]; then
name="${path##*/}"; name="${name%.conf}"

# don't start configs which are set to disabled in uci
elif echo "$UCI_DISABLED" | grep -qxF "$path"; then
logger -t openvpn "$name.conf is disabled in /etc/config/openvpn"
continue
fi
# don't start configs again that are already started by uci
if echo "$UCI_STARTED" | grep -qxF "$path"; then
continue

openvpn_add_instance "$name" "${path%/*}" "$path"
fi
done
# don't start configs which are set to disabled in uci
elif echo "$UCI_DISABLED" | grep -qxF "$path"; then
logger -t openvpn "$name.conf is disabled in /etc/config/openvpn"
continue
fi

openvpn_add_instance "$name" "${path%/*}" "$path"
fi
done
fi
}

service_triggers() {
Expand Down

0 comments on commit e2f25e6

Please sign in to comment.