From 3a08cc3074b8b5e42782893f2196851c4a3c2a85 Mon Sep 17 00:00:00 2001 From: Ycarus Date: Tue, 26 Jun 2018 12:10:31 +0200 Subject: [PATCH] Update nginx-ha luci interface to support multiple stream --- luci-app-nginx-ha/Makefile | 1 + .../luasrc/model/cbi/nginx-ha.lua | 2 +- luci-app-nginx-ha/root/etc/config/nginx-ha | 10 ++++- luci-app-nginx-ha/root/etc/init.d/nginx-ha | 44 ++++++++++++------- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/luci-app-nginx-ha/Makefile b/luci-app-nginx-ha/Makefile index c9e835813..267d00238 100644 --- a/luci-app-nginx-ha/Makefile +++ b/luci-app-nginx-ha/Makefile @@ -9,6 +9,7 @@ include $(TOPDIR)/rules.mk LUCI_TITLE:=LuCI Support for nginx load balancing LUCI_DEPENDS:=+nginx +KCONFIG:=CONFIG_NGINX_STREAM PKG_LICENSE:=MIT diff --git a/luci-app-nginx-ha/luasrc/model/cbi/nginx-ha.lua b/luci-app-nginx-ha/luasrc/model/cbi/nginx-ha.lua index 7f4a43d22..dab6918f4 100644 --- a/luci-app-nginx-ha/luasrc/model/cbi/nginx-ha.lua +++ b/luci-app-nginx-ha/luasrc/model/cbi/nginx-ha.lua @@ -7,7 +7,7 @@ else end s = m:section(TypedSection, "general", translate("General Setting")) -s.anonymous = true +s.addremove = true o = s:option(Flag, "enable", translate("Enable")) o.rmempty = false diff --git a/luci-app-nginx-ha/root/etc/config/nginx-ha b/luci-app-nginx-ha/root/etc/config/nginx-ha index b6cfa9761..8c3e60d92 100644 --- a/luci-app-nginx-ha/root/etc/config/nginx-ha +++ b/luci-app-nginx-ha/root/etc/config/nginx-ha @@ -1,8 +1,16 @@ -config general 'general' +config general 'ShadowSocks' option enable '0' option retries '1' option timeout '1000' option listen '0.0.0.0:65101' option startup_delay '5' list upstreams '1.2.3.4:65101 weight=1 max_fails=3 fail_timeout=30s' + +config general 'VPN' + option enable '0' + option retries '1' + option timeout '1000' + option listen '0.0.0.0:65001' + option startup_delay '5' + list upstreams '1.2.3.4:65001 weight=1 max_fails=3 fail_timeout=30s' diff --git a/luci-app-nginx-ha/root/etc/init.d/nginx-ha b/luci-app-nginx-ha/root/etc/init.d/nginx-ha index fee654f12..ce9805bb8 100755 --- a/luci-app-nginx-ha/root/etc/init.d/nginx-ha +++ b/luci-app-nginx-ha/root/etc/init.d/nginx-ha @@ -49,6 +49,31 @@ start_instance() { [ "$enable" = 1 ] || return 1 + stream="${stream} + upstream ${1} { + zone dynamic 64k; + $(config_list_foreach "${1}" "upstreams" genline_srv) + } + + server { + listen ${listen:-0.0.0.0:6666} udp; + proxy_pass ${1}; + } + server { + listen ${listen:-0.0.0.0:6666}; + proxy_pass ${1}; + } + " +} + +start_service() { + local stream="" + config_load nginx-ha + config_foreach start_instance general + + [ -z "$stream" ] && return + + mkdir -p /var/log/nginx mkdir -p /var/etc cat <<-EOF > /var/etc/$PROG_NAME.cfg user nobody nogroup; @@ -62,19 +87,7 @@ start_instance() { } stream { - upstream allservers { - zone dynamic 64k; - $(config_list_foreach "${1}" "upstreams" genline_srv) - } - - server { - listen ${listen:-0.0.0.0:6666} udp; - proxy_pass allservers; - } - server { - listen ${listen:-0.0.0.0:6666}; - proxy_pass allservers; - } + ${stream} } EOF @@ -83,11 +96,8 @@ start_instance() { procd_set_param file /var/etc/$PROG_NAME.cfg procd_set_param respawn procd_close_instance -} -start_service() { - config_load nginx-ha - config_foreach start_instance general + } reload_service() {