forked from mirror/MCSManager
优化 自启动功能
This commit is contained in:
parent
add64b8d44
commit
095a981738
18
app.js
18
app.js
@ -282,22 +282,8 @@ app.use("/fs", require("./onlinefs/controller/function"));
|
||||
|
||||
if (MCSERVER.allError <= 0) {
|
||||
MCSERVER.infoLog("INFO", "控制面板已经启动");
|
||||
// 异步等待3秒,打开已配置打开 MCSM 时自启的服务器
|
||||
setTimeout(() => {
|
||||
var serverModel = require("./model/ServerModel");
|
||||
let servers = serverModel.ServerManager().getServerObjects();
|
||||
for (let k in servers) {
|
||||
try {
|
||||
let server = servers[k];
|
||||
if (server.dataModel.autoStart) {
|
||||
server.start();
|
||||
}
|
||||
} catch (serverErr) {
|
||||
MCSERVER.error("自动开启某服务器失败:", serverErr);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}, 3000);
|
||||
// 执行自启动任务
|
||||
require("./helper/AutoStartTask").startAutoTask();
|
||||
} else {
|
||||
MCSERVER.infoLog("INFO", "控制面板启动异常");
|
||||
}
|
||||
|
30
helper/AutoStartTask.js
Normal file
30
helper/AutoStartTask.js
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* @Author: Copyright(c) 2021 keywet06 & Suwings
|
||||
* @Date: 2021-06-23 09:51:55
|
||||
* @LastEditTime: 2021-06-23 10:04:31
|
||||
* @Description: 自启动任务
|
||||
*/
|
||||
|
||||
|
||||
const serverModel = require("../model/ServerModel");
|
||||
|
||||
module.exports.startAutoTask = () => {
|
||||
// 异步等待3秒,打开已配置打开 MCSM 时自启的服务器
|
||||
setTimeout(() => {
|
||||
const servers = serverModel.ServerManager().getServerObjects();
|
||||
for (const k in servers) {
|
||||
const server = servers[k];
|
||||
try {
|
||||
if (server.dataModel.autoStart) {
|
||||
server.start();
|
||||
MCSERVER.infoLog("INFO", "服务器" + server.dataModel.name + "已自动启动");
|
||||
}
|
||||
} catch (serverErr) {
|
||||
// 无需显示错误,因为启动时函数内部自动会输出错误信息
|
||||
MCSERVER.error("服务器" + server.dataModel.name + "自动启动错误");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user