From 2771256f2816a06ce43b11ff73253b1f8a60125f Mon Sep 17 00:00:00 2001 From: Leon Date: Wed, 25 Aug 2021 09:45:42 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1check=5FNinja=5Fnormal()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scripts/sh/1custom.sh | 4 ++-- Scripts/sh/1customCDN.sh | 4 ++-- Scripts/sh/scan.sh | 2 +- Tasks/qlrepo/extra.sh | 33 +++++++++++++++++++++++++++++++-- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Scripts/sh/1custom.sh b/Scripts/sh/1custom.sh index 4c82804..78dfbc3 100644 --- a/Scripts/sh/1custom.sh +++ b/Scripts/sh/1custom.sh @@ -80,8 +80,8 @@ set_default_extra() { sed -i "s/CollectedRepo=(4)/CollectedRepo=(${CollectedRepo})/g" $extra_shell_path sed -i "s/OtherRepo=()/OtherRepo=(${OtherRepo})/g" $extra_shell_path echo -e "Ninja\n###(1)默认启动并自动更新\n###(2)!!!未修改容器映射的请勿运行,否则会出现青龙打不开或者设备死机等不良后果,映射参考 https://github.com/MoonBegonia/ninja#%E5%AE%B9%E5%99%A8%E5%86%85" - read -p "Ninja="up" ## up为运行,down为不运行,请输入您的设置(默认运行) up/down:" Ninja - sed -i "s/Ninja=\"up\"/Ninja=\"${Ninja}\"/" $extra_shell_path + read -p "Ninja="on" ##up为更新,on为启动,down为不运行,请输入您的设置(默认运行) up/on/down:" Ninja + sed -i "s/Ninja=\"on\"/Ninja=\"${Ninja}\"/" $extra_shell_path } # 将 ql extra 添加到定时任务 add_ql_extra() { diff --git a/Scripts/sh/1customCDN.sh b/Scripts/sh/1customCDN.sh index eb15614..17cd62a 100644 --- a/Scripts/sh/1customCDN.sh +++ b/Scripts/sh/1customCDN.sh @@ -115,8 +115,8 @@ set_default_extra() { sed -i "s/CollectedRepo=(4)/CollectedRepo=(${CollectedRepo})/g" $extra_shell_path sed -i "s/OtherRepo=()/OtherRepo=(${OtherRepo})/g" $extra_shell_path echo -e "Ninja\n###(1)默认启动并自动更新\n###(2)!!!未修改容器映射的请勿运行,否则会出现青龙打不开或者设备死机等不良后果,映射参考 https://github.com/MoonBegonia/ninja#%E5%AE%B9%E5%99%A8%E5%86%85" - read -p "Ninja="up" ## up为运行,down为不运行,请输入您的设置(默认运行) up/down:" Ninja - sed -i "s/Ninja=\"up\"/Ninja=\"${Ninja}\"/" $extra_shell_path + read -p "Ninja="on" ##up为更新,on为启动,down为不运行,请输入您的设置(默认运行) up/on/down:" Ninja + sed -i "s/Ninja=\"on\"/Ninja=\"${Ninja}\"/" $extra_shell_path } # 将 ql extra 添加到定时任务 add_ql_extra() { diff --git a/Scripts/sh/scan.sh b/Scripts/sh/scan.sh index 80ce2ae..f47d645 100644 --- a/Scripts/sh/scan.sh +++ b/Scripts/sh/scan.sh @@ -25,7 +25,7 @@ while ((i<=0)); do fi else i=1 - echo $NOWTIME" 扫描结束!NINJA还在!" + echo $NOWTIME" 扫描结束!NINJA 还在!" fi done diff --git a/Tasks/qlrepo/extra.sh b/Tasks/qlrepo/extra.sh index d4e33af..939535e 100644 --- a/Tasks/qlrepo/extra.sh +++ b/Tasks/qlrepo/extra.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -## Mod: Build20210825V1 +## Mod: Build20210825V2 ## 添加你需要重启自动执行的任意命令,比如 ql repo ## 安装node依赖使用 pnpm install -g xxx xxx(Build 20210728-002 及以上版本的 code.sh,可忽略) ## 安装python依赖使用 pip3 install xxx(Build 20210728-002 及以上版本的 code.sh,可忽略) @@ -26,7 +26,7 @@ OtherRepo=() ##示例:OtherRepo=(1 3) dependencies="no" ##yes为安装,no为不安装 package_name="canvas png-js date-fns axios crypto-js ts-md5 tslib @types/node dotenv typescript fs require tslib" ## 3. Ninja 是否需要启动和更新设置 -Ninja="up" ##up为运行,down为不运行 +Ninja="on" ##up为更新,on为启动,down为不运行 #------ 编号区 ------# @@ -131,8 +131,37 @@ update_Ninja_normal(){ cp sendNotify.js /ql/scripts/sendNotify.js } +check_Ninja_normal(){ + NOWTIME=$(date +%Y-%m-%d-%H-%M-%S) + i=0 + while ((i<=0)); do + echo "扫描 Ninja 是否在线" + ps -fe|grep ninja|grep -v grep + if [ $? -ne 0 ]; then + i=0 + echo $NOWTIME" 扫描结束!Ninja 掉线了不用担心马上重启!" + cd /ql + ps -ef|grep ninja|grep -v grep|awk '{print $1}'|xargs kill -9 + cd /ql/ninja/backend + pnpm install + pm2 start + ps -fe|grep Daemon |grep -v grep + if [ $? -ne 1 ]; then + i=1 + echo $NOWTIME" Ninja 重启完成!" + curl "https://api.telegram.org/bot$TG_BOT_TOKEN/sendMessage?chat_id=$TG_USER_ID&text=Ninja 已重启完成" + fi + else + i=1 + echo $NOWTIME" 扫描结束!Ninja 还在!" + fi + done +} + if [ "$Ninja" = "up" ]; then update_Ninja_normal & +elif [ "$Ninja" = "on" ]; then + check_Ninja_normal fi