mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Add haproxy and add pot for glorytun
This commit is contained in:
parent
5dc4952622
commit
1de17a4886
14 changed files with 716 additions and 1 deletions
110
luci-app-haproxy-tcp/root/etc/init.d/haproxy-tcp
Normal file
110
luci-app-haproxy-tcp/root/etc/init.d/haproxy-tcp
Normal file
|
@ -0,0 +1,110 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2016 chenhw2 <chenhw2@github.com>
|
||||
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
|
||||
|
||||
START=85
|
||||
|
||||
USE_PROCD=1
|
||||
PROG_NAME=haproxy-tcp
|
||||
PROG=/usr/sbin/${PROG_NAME}
|
||||
|
||||
PIDCOUNT=0
|
||||
|
||||
_log() {
|
||||
logger -p daemon.info -t ${PROG_NAME} "$@"
|
||||
}
|
||||
|
||||
_err() {
|
||||
logger -p daemon.err -t ${PROG_NAME} "$@"
|
||||
}
|
||||
|
||||
validate_section() {
|
||||
uci_validate_section haproxy-tcp general "${1}" \
|
||||
'enable:bool:0' \
|
||||
'retries:uinteger:1' \
|
||||
'timeout:uinteger:1000' \
|
||||
'startup_delay:uinteger:5' \
|
||||
'admin_stats:port:7777' \
|
||||
'listen:string' \
|
||||
'upstreams:list(string)'
|
||||
}
|
||||
|
||||
genline_srv(){
|
||||
line="$1"
|
||||
hash="$(echo -n $line | md5sum | cut -c1-6)"
|
||||
hash="$(echo -n $line | tr -d '\t ' | cut -c1-8)__$hash"
|
||||
echo " server $hash $line" | tr -d "\'"
|
||||
}
|
||||
|
||||
boot() {
|
||||
local delay=$(uci -q get $NAME.general.startup_delay)
|
||||
(sleep ${delay:-0} && start >/dev/null 2>&1) &
|
||||
return 0
|
||||
}
|
||||
|
||||
start_instance() {
|
||||
local enable retries timeout admin_stats startup_delay listen upstreams
|
||||
|
||||
validate_section "${1}" || {
|
||||
_err "validation failed"
|
||||
return 1
|
||||
}
|
||||
|
||||
[ "$enable" = 1 ] || return 1
|
||||
|
||||
PIDCOUNT="$(( ${PIDCOUNT} + 1))"
|
||||
|
||||
mkdir -p /var/etc
|
||||
cat <<-EOF > /var/etc/$PROG_NAME.cfg
|
||||
global
|
||||
nbproc $(grep -c '^processor' /proc/cpuinfo | tr -d "\n")
|
||||
|
||||
defaults
|
||||
mode tcp
|
||||
retries ${retries:-2}
|
||||
timeout connect ${timeout:-1000}
|
||||
|
||||
listen admin_stats
|
||||
bind 0.0.0.0:${admin_stats:-7777}
|
||||
mode http
|
||||
stats uri /
|
||||
stats refresh 10s
|
||||
|
||||
frontend tcp-in
|
||||
bind ${listen:-0.0.0.0:6666}
|
||||
default_backend tcp-out
|
||||
|
||||
backend tcp-out
|
||||
$( if [ 0 -lt $(grep -c weight /etc/config/$PROG_NAME) ]; then
|
||||
echo " balance static-rr"
|
||||
sed -n 's/.*upstreams[\t ]*//p' /etc/config/$PROG_NAME |
|
||||
while read upstream; do
|
||||
genline_srv "$upstream"
|
||||
done
|
||||
else
|
||||
config_list_foreach "${1}" "upstreams" genline_srv
|
||||
fi
|
||||
)
|
||||
|
||||
EOF
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command ${PROG} \
|
||||
-q -D -f /var/etc/$PROG_NAME.cfg \
|
||||
-p /var/run/${PROG}.${PIDCOUNT}.pid
|
||||
|
||||
procd_set_param respawn 0 30 0
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load haproxy-tcp
|
||||
config_foreach start_instance general
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger haproxy-tcp general
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue