Update app.js
This commit is contained in:
@@ -5,29 +5,54 @@ const app = express();
|
|||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
const commandToRun = "cd ~ && bash serv00keep.sh";
|
const commandToRun = "cd ~ && bash serv00keep.sh";
|
||||||
function runCustomCommand() {
|
function runCustomCommand() {
|
||||||
exec(commandToRun, function (err, stdout, stderr) {
|
exec(commandToRun, (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) console.error("执行错误:", err);
|
||||||
console.log("命令执行错误: " + err);
|
else console.log("执行成功:", stdout);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (stderr) {
|
|
||||||
console.log("命令执行标准错误输出: " + stderr);
|
|
||||||
}
|
|
||||||
console.log("命令执行成功:\n" + stdout);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setInterval(runCustomCommand, 3 * 60 * 1000); // 3 分钟 = 3 * 60 * 1000 毫秒
|
app.get("/up", (req, res) => {
|
||||||
app.get("/up", function (req, res) {
|
|
||||||
runCustomCommand();
|
runCustomCommand();
|
||||||
res.type("html").send("<pre>Serv00-name服务器网页保活启动:Serv00-name!UP!UP!UP!</pre>");
|
res.type("html").send("<pre>Serv00-name服务器网页保活启动:Serv00-name!UP!UP!UP!</pre>");
|
||||||
});
|
});
|
||||||
app.use((req, res, next) => {
|
app.get("/re", (req, res) => {
|
||||||
if (req.path === '/up') {
|
const additionalCommands = `
|
||||||
return next();
|
USERNAME=$(whoami | tr '[:upper:]' '[:lower:]')
|
||||||
}
|
FULL_PATH="/home/\${USERNAME}/domains/\${USERNAME}.serv00.net/logs"
|
||||||
res.status(404).send('把浏览器地址改为:http://where.name.serv00.net/up 这样才能启动Serv00网页保活');
|
cd "\$FULL_PATH"
|
||||||
|
pkill -f 'run -c con' || echo "无进程可终止,准备执行重启……"
|
||||||
|
sbb="\$(cat sb.txt 2>/dev/null)"
|
||||||
|
nohup ./"\$sbb" run -c config.json >/dev/null 2>&1 &
|
||||||
|
sleep 3
|
||||||
|
echo 'Serv00主程序重启成功,请检测三个主节点是否可用,如不可用,可再次刷新重启网页或者卸载重装脚本'
|
||||||
|
`;
|
||||||
|
exec(additionalCommands, (err, stdout, stderr) => {
|
||||||
|
console.log('stdout:', stdout);
|
||||||
|
console.error('stderr:', stderr);
|
||||||
|
if (err) {
|
||||||
|
return res.status(500).send(`错误:${stderr || stdout}`);
|
||||||
|
}
|
||||||
|
res.type('text').send(stdout);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
app.get("/list/key", (req, res) => {
|
||||||
|
const listCommands = `
|
||||||
|
USERNAME=$(whoami | tr '[:upper:]' '[:lower:]')
|
||||||
|
FULL_PATH="/home/\${USERNAME}/domains/\${USERNAME}.serv00.net/logs/list.txt"
|
||||||
|
cat "\$FULL_PATH"
|
||||||
|
`;
|
||||||
|
exec(listCommands, (err, stdout, stderr) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(`路径验证失败: ${stderr}`);
|
||||||
|
return res.status(404).send(stderr);
|
||||||
|
}
|
||||||
|
res.type('text').send(stdout);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
app.use((req, res) => {
|
||||||
|
res.status(404).send('浏览器地址:http://where.name.serv00.net 三种路径功能:/up是保活,/re是重启,/list/key是节点及订阅信息');
|
||||||
|
});
|
||||||
|
setInterval(runCustomCommand, 3 * 60 * 1000);
|
||||||
app.listen(3000, () => {
|
app.listen(3000, () => {
|
||||||
console.log("服务器已启动,监听端口 3000");
|
console.log("服务器运行在端口 3000");
|
||||||
runCustomCommand();
|
runCustomCommand();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user