From bb247dcd3ad76159c3e773aef4efbb678cbbc832 Mon Sep 17 00:00:00 2001 From: LEAN-ESX Date: Wed, 4 Mar 2020 04:19:31 -0800 Subject: [PATCH] luci-app-ssr-plus: add monitor for dns2socks --- package/lean/luci-app-ssr-plus/Makefile | 2 +- .../root/etc/init.d/shadowsocksr | 1 + .../root/usr/bin/ssr-monitor | 28 ++++++++++++++----- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/package/lean/luci-app-ssr-plus/Makefile b/package/lean/luci-app-ssr-plus/Makefile index 09127c38c..4b0168410 100644 --- a/package/lean/luci-app-ssr-plus/Makefile +++ b/package/lean/luci-app-ssr-plus/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-ssr-plus PKG_VERSION:=160 -PKG_RELEASE:=6 +PKG_RELEASE:=7 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) diff --git a/package/lean/luci-app-ssr-plus/root/etc/init.d/shadowsocksr b/package/lean/luci-app-ssr-plus/root/etc/init.d/shadowsocksr index 5649804af..9b7d63c5c 100755 --- a/package/lean/luci-app-ssr-plus/root/etc/init.d/shadowsocksr +++ b/package/lean/luci-app-ssr-plus/root/etc/init.d/shadowsocksr @@ -373,6 +373,7 @@ start_redir() { elif [ "$ssr_dns" == "2" ]; then microsocks -i 127.0.0.1 -p 10802 ssr-dns >/dev/null 2>&1 & dns2socks 127.0.0.1:10802 $dnsserver:$dnsport 127.0.0.1:5335 -q >/dev/null 2>&1 & + pdnsd_enable_flag=2 fi if [ "$(uci_get_by_type global enable_switch)" == "1" ]; then if [ "$(uci_get_by_name $GLOBAL_SERVER switch_enable 1)" == "1" ]; then diff --git a/package/lean/luci-app-ssr-plus/root/usr/bin/ssr-monitor b/package/lean/luci-app-ssr-plus/root/usr/bin/ssr-monitor index a6d581aa6..d4b581293 100755 --- a/package/lean/luci-app-ssr-plus/root/usr/bin/ssr-monitor +++ b/package/lean/luci-app-ssr-plus/root/usr/bin/ssr-monitor @@ -95,22 +95,22 @@ while [ "1" == "1" ]; do #死循环 (/usr/bin/kcptun-client -r $server:$kcp_port -l :$server_port $password $kcp_param &) fi fi - #microsocks + #localsocks if [ "$local_process" -gt 0 ]; then - icount=$(busybox ps -w | grep microsocks | grep -v grep | wc -l) + icount=$(busybox ps -w | grep ssr-socks | grep -v grep | wc -l) if [ "$icount" -lt "$local_process" ]; then #如果进程挂掉就重启它 logger -t "$NAME" "microsocks error.restart!" - killall -q -9 microsocks - local auth_enable=$(uci_get_by_type socks5_proxy auth_enable 0) + kill -9 $(busybox ps -w | grep ssr-socks | grep -v grep | awk '{print $1}') >/dev/null 2>&1 + auth_enable=$(uci_get_by_type socks5_proxy auth_enable 0) if [ "$auth_enable" == "1" ]; then - microsocks -i 0.0.0.0 -p $(uci_get_by_type socks5_proxy local_port 1080) -1 -u $(uci_get_by_type socks5_proxy username) -P $(uci_get_by_type socks5_proxy password) >/dev/null 2>&1 & + microsocks -i 0.0.0.0 -p $(uci_get_by_type socks5_proxy local_port 1080) -1 -u $(uci_get_by_type socks5_proxy username) -P $(uci_get_by_type socks5_proxy password) ssr-socks >/dev/null 2>&1 & else - microsocks -i 0.0.0.0 -p $(uci_get_by_type socks5_proxy local_port 1080) >/dev/null 2>&1 & + microsocks -i 0.0.0.0 -p $(uci_get_by_type socks5_proxy local_port 1080) ssr-socks >/dev/null 2>&1 & fi fi fi #pdnsd - if [ "$pdnsd_process" -gt 0 ]; then + if [ "$pdnsd_process" -eq 1 ]; then icount=$(busybox ps -w | grep pdnsd | grep -v grep | wc -l) if [ "$icount" -lt "$pdnsd_process" ]; then #如果进程挂掉就重启它 logger -t "$NAME" "pdnsd tunnel error.restart!" @@ -122,4 +122,18 @@ while [ "1" == "1" ]; do #死循环 (/usr/sbin/pdnsd -c /var/etc/pdnsd.conf -d &) fi fi + #dns2socks + if [ "$pdnsd_process" -eq 2 ]; then + icount=$(busybox ps -w | grep -e ssr-dns -e dns2socks | grep -v grep | wc -l) + if [ "$icount" -lt 2 ]; then #如果进程挂掉就重启它 + logger -t "$NAME" "dns2socks $dnsstr tunnel error.restart!" + dnsstr=$(uci_get_by_type global tunnel_forward 8.8.4.4:53) + dnsserver=$(echo "$dnsstr" | awk -F ':' '{print $1}') + dnsport=$(echo "$dnsstr" | awk -F ':' '{print $2}') + killall -q -9 dns2socks + kill -9 $(busybox ps -w | grep ssr-dns | grep -v grep | awk '{print $1}') >/dev/null 2>&1 + microsocks -i 127.0.0.1 -p 10802 ssr-dns >/dev/null 2>&1 & + dns2socks 127.0.0.1:10802 $dnsserver:$dnsport 127.0.0.1:5335 -q >/dev/null 2>&1 & + fi + fi done