From cafef2f4133a9076d84b5d23301849814d857f64 Mon Sep 17 00:00:00 2001 From: juewuy Date: Mon, 21 Sep 2020 16:21:26 +0800 Subject: [PATCH] =?UTF-8?q?v1.0.0beta9=20~=E4=BF=AE=E5=A4=8D=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E6=9B=B4=E6=96=B0=E8=AE=A2=E9=98=85=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=87=BA=E9=94=99=E7=9A=84bug=20~=E8=B0=83=E6=95=B4=E6=9C=AC?= =?UTF-8?q?=E6=9C=BA=E4=BB=A3=E7=90=86=E5=8A=9F=E8=83=BD=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=20~=E4=BF=AE=E5=A4=8DGoogleHome=E6=97=A0=E6=B3=95=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98=20~=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E8=84=9A=E6=9C=AC=EF=BC=8C=E9=80=82=E9=85=8D?= =?UTF-8?q?=E6=97=A7=E7=89=88=E6=9C=AC=E8=AE=BE=E5=A4=87=20~=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=9D=9EOpenwrt=E7=B3=BB=E7=BB=9F=E4=B8=8B=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84?= =?UTF-8?q?bug=20~=E4=BF=AE=E5=A4=8D=E4=BF=9D=E5=AE=88=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E5=AE=88=E6=8A=A4=E8=BF=9B=E7=A8=8B=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=E7=9A=84bug=20~=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E6=97=B6=E7=9A=84=E5=90=AF=E5=8A=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/clash.sh | 7 ++--- scripts/clashservice | 15 +++++------ scripts/start.sh | 61 +++++++++++++++++++++++++------------------- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/scripts/clash.sh b/scripts/clash.sh index b333088..31af206 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -6,7 +6,6 @@ getconfig(){ if [ -f /bin/opkg ];then host=$(ubus call network.interface.lan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';) else - cron_user='root ' host=$(ip a|grep -w 'inet'|grep 'global'|grep -E '192.|10.'|sed 's/.*inet.//g'|sed 's/\/[0-9][0-9].*$//g') [ -z $host ] && host=127.0.0.1 fi @@ -115,7 +114,8 @@ clashstart(){ $clashdir/start.sh start sleep 1 PID=$(pidof clash) - if [ -z "$PID" ];then + if [ -z "$PID" ];then + $clashdir/start.sh stop echo -e "\033[31mclash启动失败!\033[0m" exit fi @@ -793,9 +793,10 @@ clashcron(){ read -p "是否确认添加定时任务?(1/0) > " res if [ "$res" = '1' ]; then sed -i /$cronname/d $cronpath - echo "$min $hour * * $week $cron_user$cronset >/dev/null 2>&1 #$week1的$hour点$min分$cronname" >> $cronpath + echo "$min $hour * * $week $cronset >/dev/null 2>&1 #$week1的$hour点$min分$cronname" >> $cronpath echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo -e "\033[31m定时任务已添加!!!\033[0m" + chmod 600 $cronpath #修改权限 fi clashcron } diff --git a/scripts/clashservice b/scripts/clashservice index 6a6d364..9f4d56b 100644 --- a/scripts/clashservice +++ b/scripts/clashservice @@ -5,29 +5,28 @@ START=92 SERVICE_DAEMONIZE=1 SERVICE_WRITE_PID=1 USE_PROCD=1 - +DIR=$(cat /etc/profile|grep clashdir|awk -F "\"" '{print $2}') start_service() { - clashdir=$(cat /etc/profile|grep clashdir|awk -F "\"" '{print $2}') #使用procd创建clash后台进程 procd_open_instance procd_set_param respawn procd_set_param stderr 1 procd_set_param stdout 1 - procd_set_param command $clashdir/clash -d $clashdir + procd_set_param command $DIR/clash -d $DIR procd_close_instance #其他设置 - $clashdir/start.sh afstart + $DIR/start.sh afstart } start() { if [ -z "$(pidof procd)" ];then - clashdir=$(cat /etc/profile|grep clashdir|awk -F "\"" '{print $2}') #创建后台进程 - service_start $clashdir/clash -d $clashdir - #$clashdir/start.sh deamon + service_start $DIR/clash -d $DIR + #设置守护进程 + $DIR/start.sh deamon #其他设置 - $clashdir/start.sh afstart + $DIR/start.sh afstart else start_service fi diff --git a/scripts/start.sh b/scripts/start.sh index 77713fc..c7321ee 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -117,28 +117,38 @@ else $0 stop start_over(){ echo -e "\033[32mclash服务已启动!\033[0m" - echo -e "可以使用\033[30;47m http://clash.razord.top \033[0m管理内置规则" - echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m 9999 \033[0m" - echo -e "也可前往更新菜单安装本地Dashboard面板,连接更稳定!\033[0m" - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + if [ -d /www/clash ];then + echo -e "请使用\033[30;47m http://$host/clash \033[0m管理内置规则" + elif [ -d $clashdir/ui ];then + echo -e "请使用\033[30;47m http://$host:9999/ui \033[0m管理内置规则" + else + echo -e "可使用\033[30;47m http://clash.razord.top \033[0m管理内置规则" + echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m 9999 \033[0m" + echo -e "也可前往更新菜单安装本地Dashboard面板,连接更稳定!\033[0m" + echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + fi } $0 start sleep 1 - PID=$(pidof clash) - if [ -n "$PID" ];then + if pidof clash >/dev/null;then start_over else echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ -f $yaml.bak ];then - echo -e "\033[31mclash服务启动失败!已还原配置文件并重启clash!\033[0m" + $clashdir/start.sh stop mv $yaml.bak $yaml $0 start + echo -e "\033[31mclash服务启动失败!已还原配置文件并重启clash!\033[0m" sleep 1 - else - echo -e "\033[31mclash服务启动失败!请查看报错信息!\033[0m" - $clashdir/clash -d $clashdir & { sleep 3 ; kill $! & } + if pidof clash >/dev/null;then + start_over exit; + fi fi + echo -e "\033[31mclash服务启动失败!请查看报错信息!\033[0m" + $clashdir/start.sh stop + $clashdir/clash -d $clashdir & { sleep 3 ; kill $! & } + exit; fi else echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -286,23 +296,21 @@ start_dns(){ ip6tables -t nat -A PREROUTING -p udp -j clash_dns > /dev/null 2>&1 fi } -daemon_old(){ - #守护进程状态 - PID=$(pidof clash) - if [ -z "$PID" ];then - $clashdir/clash -d $clashdir > /dev/null & - mark_time - fi -} checkcron(){ [ -d /etc/crontabs/ ]&&cronpath="/etc/crontabs/root" [ -d /var/spool/cron/ ]&&cronpath="/var/spool/cron/root" [ -d /var/spool/cron/crontabs/ ]&&cronpath="/var/spool/cron/crontabs/root" - if [ -z $cronpath ];then - echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - echo "找不到定时任务文件,无法添加定时任务!" - clashsh - fi + [ -z $cronpath ]&&echo "找不到定时任务文件,无法添加定时任务!" +} +daemon(){ + checkcron + echo '*/1 * * * * test -z "$(pidof clash)" && /etc/init.d/clash start #clash守护进程' >> $cronpath + chmod 600 $cronpath +} +daemon_old(){ + checkcron + echo '*/1 * * * * test -z "$(pidof clash)" && '"$clashdir/clash -d $clashdir >/dev/null 2>&1 & #clash守护进程" >> $cronpath + chmod 600 $cronpath } afstart(){ #读取配置文件 @@ -328,6 +336,7 @@ start) #使用不同方式启动clash服务 if [ "$start_old" = "已开启" ];then $clashdir/clash -d $clashdir >/dev/null 2>&1 & + daemon_old afstart elif [ -f /etc/rc.common ];then /etc/init.d/clash start @@ -338,7 +347,7 @@ start) stop) #删除守护 checkcron - sed -i /start.sh/d $cronpath >/dev/null 2>&1 + sed -i /clash守护进程/d $cronpath #多种方式结束进程 if [ -f /etc/rc.common ];then /etc/init.d/clash stop >/dev/null 2>&1 @@ -357,8 +366,8 @@ getyaml) getconfig getyaml ;; -daemon_old) - daemon_old +daemon) + daemon ;; esac exit 0 \ No newline at end of file