diff --git a/daemon/src/entity/commands/dispatcher.ts b/daemon/src/entity/commands/dispatcher.ts index e7dcd9f2..2cb06181 100755 --- a/daemon/src/entity/commands/dispatcher.ts +++ b/daemon/src/entity/commands/dispatcher.ts @@ -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 diff --git a/daemon/src/entity/commands/general/general_kill.ts b/daemon/src/entity/commands/general/general_kill.ts index b9dc2254..1b647b7f 100755 --- a/daemon/src/entity/commands/general/general_kill.ts +++ b/daemon/src/entity/commands/general/general_kill.ts @@ -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 diff --git a/daemon/src/entity/commands/general/general_restart.ts b/daemon/src/entity/commands/general/general_restart.ts index cb87a2cb..db68403e 100755 --- a/daemon/src/entity/commands/general/general_restart.ts +++ b/daemon/src/entity/commands/general/general_restart.ts @@ -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"); diff --git a/daemon/src/entity/commands/general/general_stop.ts b/daemon/src/entity/commands/general/general_stop.ts index c48d27da..dfa8a617 100755 --- a/daemon/src/entity/commands/general/general_stop.ts +++ b/daemon/src/entity/commands/general/general_stop.ts @@ -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 diff --git a/daemon/src/entity/commands/pty/pty_stop.ts b/daemon/src/entity/commands/pty/pty_stop.ts deleted file mode 100755 index 617087a0..00000000 --- a/daemon/src/entity/commands/pty/pty_stop.ts +++ /dev/null @@ -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; - } -} diff --git a/daemon/src/entity/instance/instance.ts b/daemon/src/entity/instance/instance.ts index a27a7b57..a17f5825 100755 --- a/daemon/src/entity/instance/instance.ts +++ b/daemon/src/entity/instance/instance.ts @@ -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`; diff --git a/languages/zh_CN.json b/languages/zh_CN.json index d5132ffd..6db16864 100644 --- a/languages/zh_CN.json +++ b/languages/zh_CN.json @@ -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": "设置服务器是否应在启动时转储所有配置值到服务器日志", diff --git a/languages/zh_TW.json b/languages/zh_TW.json index 41f1a6bd..5d1b231e 100644 --- a/languages/zh_TW.json +++ b/languages/zh_TW.json @@ -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": "設定伺服器是否應在啟動時轉存所有設定值到伺服器日誌",