mirror of
https://github.com/frankiejun/node-ws.git
synced 2026-05-22 18:09:18 +08:00
+探针
This commit is contained in:
13
cron.sh
13
cron.sh
@@ -10,10 +10,21 @@ checkProcAlive() {
|
||||
}
|
||||
username=$(whoami)
|
||||
|
||||
nezha_check=false
|
||||
|
||||
if ! checkProcAlive index.js ; then
|
||||
echo "check" >> /home/$username/a.log
|
||||
# echo "check" >> /home/$username/a.log
|
||||
cd /home/$username/public_html
|
||||
if [ -e "node_modules" ]; then
|
||||
nohup /opt/alt/alt-nodejs20/root/usr/bin/node index.js > out.log 2>&1 &
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$nezha_check" != "false" ]; then
|
||||
if ! checkProcAlive npm ; then
|
||||
cd /home/$username/public_html
|
||||
if [ -e "npm" ] && [ -e "config.yaml" ]; then
|
||||
nohup ./npm -c config.yaml > /dev/null 2>&1 &
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
27
index.js
27
index.js
@@ -112,6 +112,23 @@ const runnz = async () => {
|
||||
let NEZHA_TLS = '';
|
||||
let command = '';
|
||||
|
||||
console.log(`NEZHA_SERVER: ${NEZHA_SERVER}`);
|
||||
|
||||
|
||||
const checkNpmRunning = () => {
|
||||
try {
|
||||
const result = execSync('ps aux | grep "npm" | grep -v "grep"').toString();
|
||||
return result.length > 0;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
if (checkNpmRunning()) {
|
||||
console.log('npm is already running');
|
||||
return;
|
||||
}
|
||||
|
||||
if (NEZHA_SERVER && NEZHA_PORT && NEZHA_KEY) {
|
||||
const tlsPorts = ['443', '8443', '2096', '2087', '2083', '2053'];
|
||||
NEZHA_TLS = tlsPorts.includes(NEZHA_PORT) ? '--tls' : '';
|
||||
@@ -143,7 +160,9 @@ use_gitee_to_upgrade: false
|
||||
use_ipv6_country_code: false
|
||||
uuid: ${UUID}`;
|
||||
|
||||
fs.writeFileSync('config.yaml', configYaml);
|
||||
if (!fs.existsSync('config.yaml')) {
|
||||
fs.writeFileSync('config.yaml', configYaml);
|
||||
}
|
||||
}
|
||||
command = `nohup ./npm -c config.yaml >/dev/null 2>&1 &`;
|
||||
} else {
|
||||
@@ -190,9 +209,9 @@ const delFiles = () => {
|
||||
|
||||
httpServer.listen(PORT, () => {
|
||||
runnz();
|
||||
setTimeout(() => {
|
||||
delFiles();
|
||||
}, 30000);
|
||||
// setTimeout(() => {
|
||||
// delFiles();
|
||||
// }, 30000);
|
||||
addAccessTask();
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
});
|
||||
|
||||
35
setup.sh
35
setup.sh
@@ -17,7 +17,6 @@ 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 失败!"
|
||||
@@ -26,9 +25,41 @@ fi
|
||||
chmod +x /home/$username/cron.sh
|
||||
|
||||
|
||||
read -p "输入UUID:" uuid
|
||||
if [ -z "$uuid" ]; then
|
||||
echo "Error: UUID不能为空!"
|
||||
exit 1
|
||||
fi
|
||||
echo "你输入的UUID: $uuid"
|
||||
read -p "是否安装探针? [y/n] [n]:" input
|
||||
input=${input:-n}
|
||||
if [ "$input" != "n" ]; then
|
||||
read -p "输入NEZHA_SERVER(哪吒v1填写形式:nz.abc.com:8008,哪吒v0填写形式:nz.abc.com):" nezha_server
|
||||
if [ -z "$nezha_server" ]; then
|
||||
echo "Error: nezha_server不能为空!"
|
||||
exit 1
|
||||
fi
|
||||
read -p "输入NEZHA_PORT( v1面板此处按回车, v0的agent端口为{443,8443,2096,2087,2083,2053}其中之一时开启tls):" nezha_port
|
||||
nezha_port=${nezha_port:-""}
|
||||
read -p "输入NEZHA_KEY(v1的NZ_CLIENT_SECRET或v0的agent端口):" nezha_key
|
||||
if [ -z "$nezha_key" ]; then
|
||||
echo "Error: nezha_key不能为空!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
echo "你输入的nezha_server: $nezha_server, nezha_port:$nezha_port, nezha_key:$nezha_key"
|
||||
|
||||
|
||||
|
||||
sed -i "s/NEZHA_SERVER || ''/NEZHA_SERVER || '$nezha_server'/g" "/home/$username/domains/$domain/public_html/index.js"
|
||||
sed -i "s/NEZHA_PORT || ''/NEZHA_PORT || '$nezha_port'/g" "/home/$username/domains/$domain/public_html/index.js"
|
||||
sed -i "s/NEZHA_KEY || ''/NEZHA_KEY || '$nezha_key'/g" "/home/$username/domains/$domain/public_html/index.js"
|
||||
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"
|
||||
sed -i "s/de04add9-5c68-6bab-950c-08cd5320df33/$uuid/g" "/home/$username/domains/$domain/public_html/index.js"
|
||||
if [ "$input" = "y" ]; then
|
||||
sed -i "s/nezha_check=false/nezha_check=true/g" "/home/$username/cron.sh"
|
||||
fi
|
||||
|
||||
|
||||
cat > "/home/$username/domains/$domain/public_html/package.json" << EOF
|
||||
@@ -54,7 +85,7 @@ cat > "/home/$username/domains/$domain/public_html/package.json" << EOF
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "*/1 * * * * /home/$username/cron.sh" > ./mycron
|
||||
echo "*/1 * * * * cd /home/$username/public_html && /home/$username/cron.sh" > ./mycron
|
||||
crontab ./mycron >/dev/null 2>&1
|
||||
rm ./mycron
|
||||
|
||||
|
||||
Reference in New Issue
Block a user