luci ssr plus: ssr-monitor replace of ssr-watchdog. optimize ssr-server method

This commit is contained in:
coolsnowwolf 2018-11-26 00:37:36 +08:00
parent 63d165d0d7
commit a5532b9697
9 changed files with 48 additions and 79 deletions

View File

@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-ssr-plus
PKG_VERSION:=1
PKG_RELEASE:=60
PKG_RELEASE:=61
PO2LMO:=$(STAGING_DIR_HOSTPKG)/bin/po2lmo

View File

@ -15,6 +15,9 @@ m = Map(shadowsocksr)
s = m:section(TypedSection, "global", translate("Server failsafe auto swith settings"))
s.anonymous = true
o = s:option(Flag, "monitor_enable", translate("Enable Process Deamon"))
o.rmempty = false
o = s:option(Flag, "enable_switch", translate("Enable Auto Switch"))
o.rmempty = false
@ -28,10 +31,6 @@ o.datatype = "uinteger"
o:depends("enable_switch", "1")
o.default = 5
-- o = s:option(Flag, "monitor_enable", translate("Enable Process Deamon"))
-- o.rmempty = false
-- [[ SOCKS5 Proxy ]]--
if nixio.fs.access("/usr/bin/ssr-local") then
s = m:section(TypedSection, "socks5_proxy", translate("SOCKS5 Proxy"))

View File

@ -6,10 +6,10 @@ local shadowsocksr = "shadowsocksr"
local sid = arg[1]
local encrypt_methods = {
"table",
"rc4",
"rc4-md5",
"rc4-md5-6",
"rc4",
"table",
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
@ -32,20 +32,12 @@ local encrypt_methods = {
local protocol = {
"origin",
"verify_deflate",
"auth_sha1_v4",
"auth_aes128_sha1",
"auth_aes128_md5",
"auth_chain_a",
}
obfs = {
"plain",
"http_simple",
"http_post",
"random_head",
"tls1.2_ticket_auth",
"tls1.2_ticket_fastauth",
}
m = Map(shadowsocksr, translate("Edit ShadowSocksR Server"))

View File

@ -38,7 +38,7 @@ o.description = translate("Through proxy update list, Not Recommended ")
o = s:option(Button,"update",translate("Update"))
o.inputstyle = "reload"
o.write = function()
luci.sys.call("bash /usr/share/shadowsocksr/subscribe.sh >/dev/null 2>&1")
luci.sys.call("bash /usr/share/shadowsocksr/subscribe.sh >>/tmp/ssrplus.log 2>&1")
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "shadowsocksr", "servers"))
end

View File

@ -314,6 +314,9 @@ msgstr "自动切换检查周期(秒)"
msgid "Check timout(second)"
msgstr "切换检查超时时间(秒)"
msgid "Enable Process Deamon"
msgstr "启用进程自动守护"
msgid "Advertising Data"
msgstr "【广告屏蔽】数据库"
@ -408,7 +411,7 @@ msgid "WAN Force Proxy IP"
msgstr "强制走代理的WAN IP"
msgid "LAN Bypassed Host List"
msgstr "不走代理的局域网 LAN IP"
msgstr "不走代理的局域网LAN IP"
msgid "LAN Force Proxy Host List"
msgstr "全局代理的LAN IP"
@ -468,7 +471,7 @@ msgid "Using incorrect encryption mothod may causes service fail to start"
msgstr "输入不正确的参数组合可能会导致服务无法启动"
msgid "Game Mode Host List"
msgstr "增强游戏模式客户端 LAN IP"
msgstr "增强游戏模式客户端LAN IP"
msgid "Server Count"
msgstr "服务器节点数"

View File

@ -4,7 +4,7 @@ config global
option tunnel_address '0.0.0.0'
option run_mode 'gfw'
option pdnsd_enable '1'
option monitor_enable '0'
option monitor_enable '1'
option global_server 'nil'
option enable_switch '1'
option switch_timeout '5'

View File

@ -43,7 +43,6 @@ uci_get_by_type() {
add_cron()
{
sed -i '/ssrplus.log/d' $CRON_FILE
echo '0 */1 * * * /usr/share/shadowsocksr/ssr-watchdog >> /tmp/ssrplus.log 2>&1' >> $CRON_FILE
echo '0 1 * * 0 echo "" > /tmp/ssrplus.log' >> $CRON_FILE
[ -n "$(grep -w "/usr/share/shadowsocksr/subscribe.sh" $CRON_FILE)" ] && sed -i '/\/usr\/share\/shadowsocksr\/subscribe.sh/d' $CRON_FILE
[ $(uci_get_by_type server_subscribe auto_update 0) -eq 1 ] && echo "0 $(uci_get_by_type server_subscribe auto_update_time) * * * /usr/share/shadowsocksr/subscribe.sh" >> $CRON_FILE
@ -307,7 +306,8 @@ start_redir() {
$sscmd -config /var/etc/v2-ssr-retcp.json >/dev/null 2>&1 &
fi
if [ -n $UDP_RELAY_SERVER ] ;then
if [ -n "$UDP_RELAY_SERVER" ] ;then
redir_udp=1
if [ "$utype" == "ss" -o "$utype" == "ssr" ] ;then
case "$(uci_get_by_name $UDP_RELAY_SERVER auth_enable)" in
@ -468,9 +468,20 @@ EOF
fi
start_server
start_local
add_cron
if [ $(uci_get_by_type global monitor_enable) = 1 ] ;then
let total_count=server_count+redir_tcp+redir_udp+tunnel_enable+kcp_enable_flag+local_enable+dns_enable_flag+switch_enable
if [ $total_count -gt 0 ]
then
#param:server(count) redir_tcp(0:no,1:yes) redir_udp tunnel kcp local gfw
service_start /usr/bin/ssr-monitor $server_count $redir_tcp $redir_udp $tunnel_enable $kcp_enable_flag $local_enable $dns_enable_flag $switch_enable
fi
fi
ENABLE_SERVER=$(uci_get_by_type global global_server)
[ "$ENABLE_SERVER" = "nil" ] && return 1
add_cron
}
boot() {
@ -488,6 +499,10 @@ stop() {
if [ -z "$switch_server" ] ;then
kill -9 $(ps | grep ssr-switch | grep -v grep | awk '{print $1}') >/dev/null 2>&1
fi
if [ $(uci_get_by_type global monitor_enable) = 1 ] ;then
kill -9 $(ps | grep ssr-monitor | grep -v grep | awk '{print $1}') >/dev/null 2>&1
fi
killall -q -9 ssr-monitor
killall -q -9 ss-redir
killall -q -9 ssr-redir
killall -q -9 v2ray

View File

@ -26,22 +26,22 @@ redir_udp_process=$3
tunnel_process=$4
kcp_process=$5
local_process=$6
pdnsd_process=$7
if [ -z "$pdnsd_process" ] ;then
pdnsd_process=0
dns_process=$7
if [ -z "$dns_process" ] ;then
dns_process=0
fi
i=0
GLOBAL_SERVER=$(uci_get_by_type global global_server)
local server=$(uci_get_by_name $GLOBAL_SERVER server)
local kcp_port=$(uci_get_by_name $GLOBAL_SERVER kcp_port)
local server_port=$(uci_get_by_name $GLOBAL_SERVER server_port)
local password=$(uci_get_by_name $GLOBAL_SERVER kcp_password)
local kcp_param=$(uci_get_by_name $GLOBAL_SERVER kcp_param)
server=$(uci_get_by_name $GLOBAL_SERVER server)
lkcp_port=$(uci_get_by_name $GLOBAL_SERVER kcp_port)
server_port=$(uci_get_by_name $GLOBAL_SERVER server_port)
password=$(uci_get_by_name $GLOBAL_SERVER kcp_password)
kcp_param=$(uci_get_by_name $GLOBAL_SERVER kcp_param)
[ "$password" != "" ] && password="--key "${password}
local sock5_port=$(uci_get_by_type socks5_proxy local_port 1080)
sock5_port=$(uci_get_by_type socks5_proxy local_port 1080)
if echo $server|grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$">/dev/null; then
server=${server}
@ -70,7 +70,7 @@ do
exit 0
fi
fi
#ssr-dns tunnel
#tunnel
if [ $tunnel_process -gt 0 ] ;then
icount=`ps -w | grep ssr-tunnel |grep -v grep| wc -l`
if [ $icount = 0 ] ;then
@ -114,38 +114,15 @@ do
( /usr/bin/ssr-local -c /var/etc/shadowsocksr_s.json -u -l $sock5_port -f /var/run/ssr-local.pid &)
fi
fi
#pdnsd
if [ $pdnsd_process -gt 0 ] ;then
icount=`ps -w | grep pdnsd |grep -v grep| wc -l`
if [ $icount -lt $pdnsd_process ] #Èç¹û½ø³Ì¹Òµô¾ÍÖØÆôËü
#dns
if [ $dns_process -gt 0 ] ;then
icount=`ps -w | grep ssr-dns |grep -v grep| wc -l`
if [ $icount -lt $dns_process ] #Èç¹û½ø³Ì¹Òµô¾ÍÖØÆôËü
then
logger -t "$NAME" "pdnsd tunnel error.restart!"
killall -q -9 pdnsd
logger -t "$NAME" "ssr dns tunnel error.restart!"
killall -q -9 ssr-tunnel
( /usr/sbin/pdnsd -c /var/etc/pdnsd.conf -d &)
( /usr/bin/ssr-tunnel -c /var/etc/shadowsocksr.json -b 0.0.0.0 -u -l 5353 -L $(uci_get_by_type global tunnel_forward 8.8.4.4:53) -f /var/run/ssr-dns.pid &)
fi
fi
#udp2raw
if [ $(uci_get_by_type udp2raw udp2raw_enable) = 1 ] ;then
ucount=`ps -w | grep udp2raw |grep -v grep| wc -l`
if [ $ucount = 0 ] ;then
/usr/bin/udp2raw --clear >/dev/null
/usr/bin/udp2raw --conf-file /var/etc/udp2raw.conf >/dev/null 2>&1 &
fi
fi
#udpspeeder
if [ $(uci_get_by_type udpspeeder udpspeeder_enable) = 1 ] ;then
scount=`ps -w | grep udpspeeder |grep -v grep| wc -l`
if [ $scount = 0 ] ;then
/usr/bin/udpspeeder -c -l0.0.0.0:$(uci_get_by_type udpspeeder local_port) \
-r$(uci_get_by_type udpspeeder server):$(uci_get_by_type udpspeeder server_port) \
-k $(uci_get_by_type udpspeeder key) \
--mode $(uci_get_by_type udpspeeder speeder_mode) \
--mtu $(uci_get_by_type udpspeeder mtu) \
-f$(uci_get_by_type udpspeeder fec) \
-q$(uci_get_by_type udpspeeder queue_len) \
--timeout $(uci_get_by_type udpspeeder timeout) \
>/dev/null 2>&1 &
fi
fi
done

View File

@ -1,17 +0,0 @@
#!/bin/sh
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
/usr/bin/ssr-check www.google.com 80 3 1
if [ "$?" == "0" ]; then
echo "$LOGTIME ShadowsocksR No Problem."
else
/usr/bin/ssr-check www.baidu.com 80 3 1
if [ "$?" == "0" ]; then
echo "$LOGTIME Problem decteted, restarting ShadowsocksR..."
/etc/init.d/shadowsocksr restart
else
echo "$LOGTIME Network Problem. Do nothing."
fi
fi