mirror of
https://github.com/MCSManager/MCSManager.git
synced 2025-03-19 16:40:22 +08:00
This commit is contained in:
parent
e61f5b3a6e
commit
1e3b99d5c6
@ -10,8 +10,6 @@ import DockerStartCommand from "./docker/docker_start";
|
||||
import TimeCheck from "./task/time";
|
||||
import GeneralUpdateCommand from "./general/general_update";
|
||||
import PtyStartCommand from "./pty/pty_start";
|
||||
import PtyStopCommand from "./pty/pty_stop";
|
||||
import OpenFrpTask from "./task/openfrp";
|
||||
import RconCommand from "./steam/rcon_command";
|
||||
import DockerResizeCommand from "./docker/docker_pty_resize";
|
||||
import PtyResizeCommand from "./pty/pty_resize";
|
||||
@ -45,7 +43,7 @@ export default class FunctionDispatcher extends InstanceCommand {
|
||||
|
||||
// the component that the instance must mount
|
||||
instance.lifeCycleTaskManager.registerLifeCycleTask(new TimeCheck());
|
||||
instance.lifeCycleTaskManager.registerLifeCycleTask(new OpenFrpTask());
|
||||
// instance.lifeCycleTaskManager.registerLifeCycleTask(new OpenFrpTask());
|
||||
|
||||
// Instance general preset capabilities
|
||||
instance.setPreset("command", new GeneralSendCommand());
|
||||
@ -64,7 +62,6 @@ export default class FunctionDispatcher extends InstanceCommand {
|
||||
// Enable emulated terminal mode
|
||||
if (instance.config.terminalOption.pty && instance.config.processType === "general") {
|
||||
instance.setPreset("start", new PtyStartCommand());
|
||||
instance.setPreset("stop", new PtyStopCommand());
|
||||
instance.setPreset("resize", new PtyResizeCommand());
|
||||
}
|
||||
// Whether to enable Docker PTY mode
|
||||
|
@ -15,6 +15,8 @@ export default class GeneralKillCommand extends InstanceCommand {
|
||||
return instance.failure(new Error($t("TXT_CODE_6259357c")));
|
||||
}
|
||||
|
||||
instance.ignoreEventTaskOnce();
|
||||
|
||||
const task = instance?.asynchronousTask;
|
||||
if (task && task.stop) {
|
||||
task
|
||||
|
@ -8,11 +8,8 @@ export default class GeneralRestartCommand extends InstanceCommand {
|
||||
}
|
||||
|
||||
async exec(instance: Instance) {
|
||||
// If the automatic restart function is enabled, the setting is ignored once
|
||||
if (instance.config.eventTask && instance.config.eventTask.autoRestart)
|
||||
instance.config.eventTask.ignore = true;
|
||||
|
||||
try {
|
||||
instance.ignoreEventTaskOnce();
|
||||
instance.println("INFO", $t("TXT_CODE_restart.start"));
|
||||
instance.setLock(true);
|
||||
await instance.execPreset("stop");
|
||||
|
@ -8,15 +8,12 @@ export default class GeneralStopCommand extends InstanceCommand {
|
||||
}
|
||||
|
||||
async exec(instance: Instance) {
|
||||
// If the automatic restart function is enabled, the setting is ignored once
|
||||
if (instance.config.eventTask && instance.config.eventTask.autoRestart)
|
||||
instance.config.eventTask.ignore = true;
|
||||
|
||||
const stopCommand = instance.config.stopCommand;
|
||||
if (instance.status() === Instance.STATUS_STOP || !instance.process)
|
||||
return instance.failure(new Error($t("TXT_CODE_general_stop.notRunning")));
|
||||
|
||||
instance.status(Instance.STATUS_STOPPING);
|
||||
instance.ignoreEventTaskOnce();
|
||||
|
||||
const stopCommandList = stopCommand.split("\n");
|
||||
for (const stopCommand of stopCommandList) {
|
||||
@ -24,7 +21,8 @@ export default class GeneralStopCommand extends InstanceCommand {
|
||||
}
|
||||
|
||||
instance.print("\n");
|
||||
instance.println("INFO", $t("TXT_CODE_general_stop.execCmd", { stopCommand }));
|
||||
instance.println("INFO", $t("TXT_CODE_pty_stop.execCmd", { stopCommand: `\n${stopCommand}` }));
|
||||
|
||||
const cacheStartCount = instance.startCount;
|
||||
|
||||
// If the instance is still in the stopped state after 10 minutes, restore the state
|
||||
|
@ -1,38 +0,0 @@
|
||||
import { $t } from "../../../i18n";
|
||||
import Instance from "../../instance/instance";
|
||||
import InstanceCommand from "../base/command";
|
||||
|
||||
export default class PtyStopCommand extends InstanceCommand {
|
||||
constructor() {
|
||||
super("PtyStopCommand");
|
||||
}
|
||||
|
||||
async exec(instance: Instance) {
|
||||
let stopCommand = instance.config.stopCommand;
|
||||
|
||||
if (instance.status() === Instance.STATUS_STOP || !instance.process)
|
||||
return instance.failure(new Error($t("TXT_CODE_pty_stop.notRunning")));
|
||||
instance.status(Instance.STATUS_STOPPING);
|
||||
|
||||
instance.println("INFO", $t("TXT_CODE_pty_stop.execCmd", { stopCommand: stopCommand }));
|
||||
|
||||
const stopCommandList = stopCommand.split("\n");
|
||||
for (const stopCommand of stopCommandList) {
|
||||
await instance.execPreset("command", stopCommand);
|
||||
}
|
||||
|
||||
// If the instance is still in the stopped state after 10 minutes, restore the state
|
||||
const cacheStartCount = instance.startCount;
|
||||
setTimeout(() => {
|
||||
if (
|
||||
instance.status() === Instance.STATUS_STOPPING &&
|
||||
instance.startCount === cacheStartCount
|
||||
) {
|
||||
instance.println("ERROR", $t("TXT_CODE_pty_stop.stopErr"));
|
||||
instance.status(Instance.STATUS_RUNNING);
|
||||
}
|
||||
}, 1000 * 60 * 10);
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
@ -288,22 +288,21 @@ export default class Instance extends EventEmitter {
|
||||
this.lifeCycleTaskManager.execLifeCycleTask(0);
|
||||
|
||||
// If automatic restart is enabled, the startup operation is performed immediately
|
||||
if (this.config.eventTask.autoRestart) {
|
||||
if (!this.config.eventTask.ignore) {
|
||||
this.execPreset("start")
|
||||
.then(() => {
|
||||
this.println($t("TXT_CODE_instanceConf.info"), $t("TXT_CODE_instanceConf.autoRestart"));
|
||||
})
|
||||
.catch((err) => {
|
||||
this.println(
|
||||
$t("TXT_CODE_instanceConf.error"),
|
||||
$t("TXT_CODE_instanceConf.autoRestartErr", { err: err })
|
||||
);
|
||||
});
|
||||
}
|
||||
this.config.eventTask.ignore = false;
|
||||
if (!this.config.eventTask.ignore && this.config.eventTask.autoRestart) {
|
||||
this.execPreset("start")
|
||||
.then(() => {
|
||||
this.println($t("TXT_CODE_instanceConf.info"), $t("TXT_CODE_instanceConf.autoRestart"));
|
||||
})
|
||||
.catch((err) => {
|
||||
this.println(
|
||||
$t("TXT_CODE_instanceConf.error"),
|
||||
$t("TXT_CODE_instanceConf.autoRestartErr", { err: err })
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
this.config.eventTask.ignore = false;
|
||||
|
||||
// Turn off the warning immediately after startup, usually the startup command is written incorrectly
|
||||
const currentTimestamp = new Date().getTime();
|
||||
const startThreshold = 2 * 1000;
|
||||
@ -312,6 +311,10 @@ export default class Instance extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
ignoreEventTaskOnce() {
|
||||
if (this.config.eventTask) this.config.eventTask.ignore = true;
|
||||
}
|
||||
|
||||
// custom output method, formatting
|
||||
println(level: string, text: string) {
|
||||
const str = `[${level}] ${text}\n`;
|
||||
|
@ -1955,7 +1955,7 @@
|
||||
"TXT_CODE_9d1d244f": "程序启动失败,输入输出流不可读:{{pipeName}}",
|
||||
"TXT_CODE_ca030197": "实例有其他任务正在进行中,无法进行此操作!",
|
||||
"TXT_CODE_aae2918f": "实例进程启动失败,请检查启动命令和运行环境等配置!",
|
||||
"TXT_CODE_e543f6c0": "MC Purpur。",
|
||||
"TXT_CODE_e543f6c0": "MC Purpur",
|
||||
"TXT_CODE_98e50717": "Purpur配置文件,允许对高级参数及更具体的游戏设置进行进一步调整,极大地影响整体性能,并在Paper配置文件的功能基础上进行扩展。",
|
||||
"TXT_CODE_da76ea07": "此配置文件常用于 Purpur 服务器,它在 Paper 配置基础上进行了更全面的扩展。",
|
||||
"TXT_CODE_81cabec": "设置服务器是否应在启动时转储所有配置值到服务器日志",
|
||||
|
@ -1955,7 +1955,7 @@
|
||||
"TXT_CODE_9d1d244f": "程式啟動失敗,無法讀取輸出入流:{{pipeName}}",
|
||||
"TXT_CODE_ca030197": "伺服器正在進行其他任務,無法進行此操作!",
|
||||
"TXT_CODE_aae2918f": "伺服器啟動失敗,請檢查啟動指令和執行環境等設定!",
|
||||
"TXT_CODE_e543f6c0": "MC Purpur。",
|
||||
"TXT_CODE_e543f6c0": "MC Purpur",
|
||||
"TXT_CODE_98e50717": "Purpur 設定檔,允許對進階參數及更具體的遊戲設定進行進一步調整,極大影響整體效能,並在 Paper 設定檔功能基礎上進行擴展。",
|
||||
"TXT_CODE_da76ea07": "此設定檔常用於 Purpur 伺服器,它在 Paper 設定基礎上進行了更全面的擴展。",
|
||||
"TXT_CODE_81cabec": "設定伺服器是否應在啟動時轉存所有設定值到伺服器日誌",
|
||||
|
Loading…
x
Reference in New Issue
Block a user