mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-19 14:13:30 +00:00
优化ssr-switch单一节点下的ss重启
针对如下场景进行优化 1、ssr-plus仅仅设置了一个服务器节点 2、该节点使用域名地址 3、域名对应的DNS解析ip修改了 问题原因: 在存在多节点情况下,select_proxy会挑选下一个节点重启ssr服务,但是在单一节点下由于不符合if [ "$ENABLE_SERVER" != nil ] 条件,导致并不调用switch_proxy来重启服务。但是域名对应的ip已经修改了,ssr服务本身是依赖ip参数启动的,ssr服务在重启依然停留在老的ip上。 调整方式: 这个修改调整为在每次检测网络失败的情况下,就算只有一个节点,也重启ssr服务,保证ssr服务有机会切换到域名新的ip地址。 此外假如因为ssr服务本身存在一些小概率bug,也可以通过重启ssr解决。 这种情况在付费的ssr服务中很常见,因为服务商往往只提供一个域名,假如因为服务器调整(比如某个服务器ip被和谐了),服务提供商都会重新给域名绑定新的服务器(或新IP)
This commit is contained in:
parent
3469334bd9
commit
734df71303
@ -33,7 +33,7 @@ uci_get_by_type() {
|
||||
DEFAULT_SERVER=$(uci_get_by_type global global_server)
|
||||
CURRENT_SERVER=$DEFAULT_SERVER
|
||||
|
||||
#判断代理是否正常
|
||||
#判断代理是否正常
|
||||
check_proxy() {
|
||||
/usr/bin/ssr-check www.google.com 80 $switch_time 1
|
||||
if [ "$?" == "0" ]; then
|
||||
@ -41,7 +41,7 @@ if [ "$?" == "0" ]; then
|
||||
else
|
||||
/usr/bin/ssr-check www.baidu.com 80 $switch_time 1
|
||||
if [ "$?" == "0" ]; then
|
||||
#goole不通baidu通则不正常
|
||||
#goole不通baidu通则不正常
|
||||
return 1
|
||||
else
|
||||
return 2
|
||||
@ -95,7 +95,7 @@ return 1
|
||||
fi
|
||||
|
||||
}
|
||||
#选择可用的代理
|
||||
#选择可用的代理
|
||||
select_proxy() {
|
||||
|
||||
config_load $NAME
|
||||
@ -106,33 +106,33 @@ config_foreach search_proxy servers
|
||||
|
||||
}
|
||||
|
||||
#切换代理
|
||||
#切换代理
|
||||
switch_proxy() {
|
||||
/etc/init.d/shadowsocksr restart $1
|
||||
return 0
|
||||
}
|
||||
|
||||
start() {
|
||||
#不支持kcptun启用时的切换
|
||||
#不支持kcptun启用时的切换
|
||||
[ $(uci_get_by_name $DEFAULT_SERVER kcp_enable) = "1" ] && return 1
|
||||
|
||||
while [ "1" = "1" ] #死循环
|
||||
while [ "1" = "1" ] #死循环
|
||||
do
|
||||
sleep $cycle_time
|
||||
|
||||
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
#判断当前代理是否为缺省服务器
|
||||
#判断当前代理是否为缺省服务器
|
||||
if [ "$CURRENT_SERVER" != "$DEFAULT_SERVER" ] ;then
|
||||
#echo "not default proxy"
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") Current server is not default Main server, try to switch back." >> /tmp/ssrplus.log
|
||||
|
||||
#检查缺省服务器是否正常
|
||||
#检查缺省服务器是否正常
|
||||
if test_proxy $DEFAULT_SERVER ;then
|
||||
#echo "switch to default proxy"
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") Main server is avilable." >> /tmp/ssrplus.log
|
||||
#缺省服务器正常,切换回来
|
||||
#缺省服务器正常,切换回来
|
||||
CURRENT_SERVER=$DEFAULT_SERVER
|
||||
switch_proxy $CURRENT_SERVER
|
||||
echo "switch to default ["$(uci_get_by_name $CURRENT_SERVER server)"] proxy!" >> /tmp/ssrplus.log
|
||||
@ -142,18 +142,18 @@ do
|
||||
fi
|
||||
fi
|
||||
|
||||
#判断当前代理是否正常
|
||||
#判断当前代理是否正常
|
||||
check_proxy
|
||||
current_ret=$?
|
||||
|
||||
if [ "$current_ret" = "1" ] ;then
|
||||
#当前代理错误,判断有无可用的服务器
|
||||
#当前代理错误,判断有无可用的服务器
|
||||
#echo "current error"
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") Current server error, try to switch another server." >> /tmp/ssrplus.log
|
||||
|
||||
select_proxy
|
||||
if [ "$ENABLE_SERVER" != nil ] ;then
|
||||
#有其他服务器可用,进行切换
|
||||
#有其他服务器可用,进行切换
|
||||
#echo $(uci_get_by_name $new_proxy server)
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") Another server is avilable, now switching server." >> /tmp/ssrplus.log
|
||||
CURRENT_SERVER=$ENABLE_SERVER
|
||||
@ -161,7 +161,9 @@ do
|
||||
normal_flag=1
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") ShadowsocksR server switch OK" >> /tmp/ssrplus.log
|
||||
else
|
||||
normal_flag=0
|
||||
switch_proxy $CURRENT_SERVER
|
||||
normal_flag=1
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") Try restart current server." >> /tmp/ssrplus.log
|
||||
fi
|
||||
else
|
||||
normal_flag=0
|
||||
@ -170,4 +172,4 @@ do
|
||||
|
||||
|
||||
done
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user