From fe53feb29b0e2be82a44d3e7acebdd7ae63b6a73 Mon Sep 17 00:00:00 2001 From: frankiejun Date: Sat, 10 May 2025 13:14:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E8=A3=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cron.sh | 19 +++++++++++++++++++ index.js | 2 +- setup.sh | 18 ++++++++++-------- 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 cron.sh diff --git a/cron.sh b/cron.sh new file mode 100644 index 0000000..1db7e6e --- /dev/null +++ b/cron.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +checkProcAlive() { + local procname=$1 + if ps aux | grep "$procname" | grep -v "grep" >/dev/null; then + return 0 + else + return 1 + fi +} +username=$(whoami) + +if ! checkProcAlive index.js ; then + echo "check" >> /home/$username/a.log + cd /home/$username/public_html + if [ -e "node_modules" ]; then + nohup /opt/alt/alt-nodejs22/root/usr/bin/node index.js > out.log 2>&1 & + fi +fi diff --git a/index.js b/index.js index 498464c..6b49042 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ const NEZHA_SERVER = process.env.NEZHA_SERVER || ''; // 哪吒v1填写形 const NEZHA_PORT = process.env.NEZHA_PORT || ''; // 哪吒v1没有此变量,v0的agent端口为{443,8443,2096,2087,2083,2053}其中之一时开启tls const NEZHA_KEY = process.env.NEZHA_KEY || ''; // v1的NZ_CLIENT_SECRET或v0的agent端口 const DOMAIN = process.env.DOMAIN || '1234.abc.com'; // 填写项目域名或已反代的域名,不带前缀,建议填已反代的域名 -const AUTO_ACCESS = process.env.AUTO_ACCESS || false; // 是否开启自动访问保活,false为关闭,true为开启,需同时填写DOMAIN变量 +const AUTO_ACCESS = process.env.AUTO_ACCESS || true; // 是否开启自动访问保活,false为关闭,true为开启,需同时填写DOMAIN变量 const SUB_PATH = process.env.SUB_PATH || 'sub'; // 获取节点的订阅路径 const NAME = process.env.NAME || 'Vls'; // 节点名称 const PORT = process.env.PORT || 3000; // http和ws服务端口 diff --git a/setup.sh b/setup.sh index 2885d85..3bafbea 100644 --- a/setup.sh +++ b/setup.sh @@ -13,12 +13,18 @@ random_port=$((RANDOM % 40001 + 20000)) echo "to /home/$username/domains/$domain/public_html/index.js" curl -s -o "/home/$username/domains/$domain/public_html/index.js" "https://raw.githubusercontent.com/frankiejun/node-ws/main/index.js" - if [ $? -ne 0 ]; then echo "Error: 下载脚本 index.js 失败!" exit 1 fi +curl -s -o "/home/$username/cron.sh" "https://raw.githubusercontent.com/frankiejun/node-ws/main/cron.sh" +if [ $? -ne 0 ]; then + echo "Error: 下载脚本 cron.sh 失败!" + exit 1 +fi + + sed -i "s/1234.abc.com/$domain/g" "/home/$username/domains/$domain/public_html/index.js" sed -i "s/3000;/$random_port;/g" "/home/$username/domains/$domain/public_html/index.js" @@ -47,12 +53,8 @@ cat > "/home/$username/domains/$domain/public_html/package.json" << EOF } EOF - -cd "/home/$username/domains/$domain/public_html/" - -if [ $? -ne 0 ]; then - echo "Error: 切换到public_html目录失败!" - exit 1 -fi +echo "*/1 * * * * /home/$username/cron.sh" > ./mycron +crontab ./mycron >/dev/null 2>&1 +rm ./mycron echo "安装完毕" \ No newline at end of file