mirror of
https://github.com/frankiejun/node-ws.git
synced 2026-06-01 18:39:28 +08:00
安装脚本
This commit is contained in:
19
cron.sh
Normal file
19
cron.sh
Normal file
@@ -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
|
||||
2
index.js
2
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服务端口
|
||||
|
||||
18
setup.sh
18
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 "安装完毕"
|
||||
Reference in New Issue
Block a user