aboutsummaryrefslogtreecommitdiffstats
path: root/package
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2015-02-07 21:01:28 +0000
committerJo-Philipp Wich <jow@openwrt.org>2015-02-07 21:01:28 +0000
commit6a61b200d89cd362fefbf4a7fa5a3493bb9ba8f1 (patch)
tree167f15be1e3a57f47d7d592d808ade47fbab290b /package
parent905361b89cded32b4cd084e0f84fac219f145baf (diff)
downloadmaster-187ad058-6a61b200d89cd362fefbf4a7fa5a3493bb9ba8f1.tar.gz
master-187ad058-6a61b200d89cd362fefbf4a7fa5a3493bb9ba8f1.tar.bz2
master-187ad058-6a61b200d89cd362fefbf4a7fa5a3493bb9ba8f1.zip
openvpn: autostart openvpn instances for each .conf file in /etc/openvpn
Align init behaviour with other distros by starting an OpenVPN instance for each config file found in /etc/openvpn/. This removes the additional requirement to "register" the configs with uci and thus simplifies the setup. Make sure to respect the disabled state in uci to not suddenly autostart instances which have been previously set to disabled, also skip configs which are already started due to uci configuration. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@44310 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package')
-rw-r--r--package/network/services/openvpn/Makefile2
-rw-r--r--package/network/services/openvpn/files/openvpn.init34
2 files changed, 32 insertions, 4 deletions
diff --git a/package/network/services/openvpn/Makefile b/package/network/services/openvpn/Makefile
index 98ccea07cb..2b0b038a29 100644
--- a/package/network/services/openvpn/Makefile
+++ b/package/network/services/openvpn/Makefile
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=openvpn
PKG_VERSION:=2.3.6
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_SOURCE_URL:=http://swupdate.openvpn.net/community/releases
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
diff --git a/package/network/services/openvpn/files/openvpn.init b/package/network/services/openvpn/files/openvpn.init
index 1e0f384f97..294e3ed710 100644
--- a/package/network/services/openvpn/files/openvpn.init
+++ b/package/network/services/openvpn/files/openvpn.init
@@ -13,6 +13,9 @@ PROG=/usr/sbin/openvpn
LIST_SEP="
"
+UCI_STARTED=
+UCI_DISABLED=
+
append_param() {
local s="$1"
local v="$2"
@@ -59,6 +62,7 @@ openvpn_add_instance() {
procd_open_instance
procd_set_param command "$PROG" \
--syslog "openvpn($name)" \
+ --status "/var/run/openvpn.$name.status" \
--cd "$dir" \
--config "$conf"
procd_set_param file "$dir/$conf"
@@ -69,14 +73,19 @@ openvpn_add_instance() {
start_instance() {
local s="$1"
- section_enabled "$s" || return 1
-
config_get config "$s" config
+ config="${config:+$(readlink -f "$config")}"
+
+ section_enabled "$s" || {
+ append UCI_DISABLED "$config" "$LIST_SEP"
+ return 1
+ }
[ ! -d "/var/run" ] && mkdir -p "/var/run"
if [ ! -z "$config" ]; then
- openvpn_add_instance "$s" "$(dirname "$config")" "$(basename "$config")"
+ append UCI_STARTED "$config" "$LIST_SEP"
+ openvpn_add_instance "$s" "${config%/*}" "$config"
return
fi
@@ -123,4 +132,23 @@ start_instance() {
start_service() {
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}"
+
+ # don't start configs again that are already started by uci
+ if echo "$UCI_STARTED" | grep -qxF "$path"; then
+ continue
+
+ # 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
}