Refactor: start instance mode

This commit is contained in:
unitwk 2022-08-11 12:07:33 +08:00
parent ce4508f457
commit 84c2c5cd65
93 changed files with 4686 additions and 68 deletions

0
.eslintrc.js Normal file → Executable file
View File

0
.github/ISSUE_TEMPLATE/------.md vendored Normal file → Executable file
View File

0
.github/ISSUE_TEMPLATE/----.md vendored Normal file → Executable file
View File

0
.github/ISSUE_TEMPLATE/bug---.md vendored Normal file → Executable file
View File

0
.github/github.txt vendored Normal file → Executable file
View File

0
.github/workflows/codacy.yml vendored Normal file → Executable file
View File

0
.github/workflows/codeql.yml vendored Normal file → Executable file
View File

0
.gitignore vendored Normal file → Executable file
View File

0
.prettierignore Normal file → Executable file
View File

0
.prettierrc.json Normal file → Executable file
View File

0
LICENSE Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

4681
package-lock.json generated Normal file → Executable file

File diff suppressed because it is too large Load Diff

0
package.json Normal file → Executable file
View File

0
readme_cn.md Normal file → Executable file
View File

0
src/app.ts Normal file → Executable file
View File

0
src/common/compress.ts Normal file → Executable file
View File

0
src/common/global_variable.ts Normal file → Executable file
View File

0
src/common/instance_stream.ts Normal file → Executable file
View File

0
src/common/mcping.ts Normal file → Executable file
View File

0
src/common/process_tools.ts Normal file → Executable file
View File

0
src/common/query_wrapper.ts Normal file → Executable file
View File

0
src/common/system_info.ts Normal file → Executable file
View File

0
src/common/system_storage.ts Normal file → Executable file
View File

0
src/common/typecheck.ts Normal file → Executable file
View File

0
src/const.ts Normal file → Executable file
View File

0
src/entity/commands/base/command.ts Normal file → Executable file
View File

0
src/entity/commands/base/command_parser.ts Normal file → Executable file
View File

0
src/entity/commands/cmd.ts Normal file → Executable file
View File

0
src/entity/commands/dispatcher.ts Normal file → Executable file
View File

0
src/entity/commands/docker/docker_resize.ts Normal file → Executable file
View File

9
src/entity/commands/docker/docker_start.ts Normal file → Executable file
View File

@ -97,13 +97,6 @@ export default class DockerStartCommand extends InstanceCommand {
if (!fs.existsSync(instance.absoluteCwdPath())) return instance.failure(new StartupDockerProcessError($t("instance.dirNoE")));
try {
// lock the instance
instance.setLock(true);
// set startup state
instance.status(Instance.STATUS_STARTING);
// increase the number of starts
instance.startCount++;
// command parsing
const commandList = commandStringToArray(instance.config.startCommand);
const cwd = instance.absoluteCwdPath();
@ -251,8 +244,6 @@ export default class DockerStartCommand extends InstanceCommand {
instance.instanceStatus = Instance.STATUS_STOP;
instance.releaseResources();
return instance.failure(err);
} finally {
instance.setLock(false);
}
}
}

0
src/entity/commands/general/general_command.ts Normal file → Executable file
View File

0
src/entity/commands/general/general_kill.ts Normal file → Executable file
View File

0
src/entity/commands/general/general_restart.ts Normal file → Executable file
View File

8
src/entity/commands/general/general_start.ts Normal file → Executable file
View File

@ -65,12 +65,6 @@ export default class GeneralStartCommand extends InstanceCommand {
if (!fs.existsSync(instance.absoluteCwdPath())) return instance.failure(new StartupError($t("general_start.cwdPathNotExist")));
try {
instance.setLock(true);
// set startup state
instance.status(Instance.STATUS_STARTING);
// increase the number of starts
instance.startCount++;
// command parsing
const commandList = commandStringToArray(instance.config.startCommand);
const commandExeFile = commandList[0];
@ -118,8 +112,6 @@ export default class GeneralStartCommand extends InstanceCommand {
instance.instanceStatus = Instance.STATUS_STOP;
instance.releaseResources();
return instance.failure(err);
} finally {
instance.setLock(false);
}
}
}

0
src/entity/commands/general/general_stop.ts Normal file → Executable file
View File

0
src/entity/commands/general/general_update.ts Normal file → Executable file
View File

0
src/entity/commands/input.ts Normal file → Executable file
View File

0
src/entity/commands/kill.ts Normal file → Executable file
View File

0
src/entity/commands/nullfunc.ts Normal file → Executable file
View File

0
src/entity/commands/process_info.ts Normal file → Executable file
View File

2
src/entity/commands/pty/pty_start.ts Normal file → Executable file
View File

@ -148,8 +148,6 @@ export default class PtyStartCommand extends InstanceCommand {
instance.instanceStatus = Instance.STATUS_STOP;
instance.releaseResources();
return instance.failure(err);
} finally {
instance.setLock(false);
}
}
}

0
src/entity/commands/pty/pty_stop.ts Normal file → Executable file
View File

0
src/entity/commands/restart.ts Normal file → Executable file
View File

44
src/entity/commands/start.ts Normal file → Executable file
View File

@ -31,25 +31,35 @@ export default class StartCommand extends InstanceCommand {
}
async exec(instance: Instance) {
// status check
const instanceStatus = instance.status();
if (instanceStatus !== Instance.STATUS_STOP) return instance.failure(new StartupError($t("start.instanceNotDown")));
if (instance.status() !== Instance.STATUS_STOP) return instance.failure(new StartupError($t("start.instanceNotDown")));
try {
instance.setLock(true);
instance.status(Instance.STATUS_STARTING);
instance.startCount++;
// expiration time check
const endTime = new Date(instance.config.endTime).getTime();
if (endTime) {
const currentTime = new Date().getTime();
if (endTime <= currentTime) {
return instance.failure(new Error($t("start.instanceMaturity")));
// expiration time check
const endTime = new Date(instance.config.endTime).getTime();
if (endTime) {
const currentTime = new Date().getTime();
if (endTime <= currentTime) {
return instance.failure(new Error($t("start.instanceMaturity")));
}
}
const currentTimestamp = new Date().getTime();
instance.startTimestamp = currentTimestamp;
instance.println("INFO", $t("start.startInstance"));
// prevent the dead-loop from starting
await this.sleep();
return await instance.execPreset("start", this.source);
} catch (error) {
instance.status(Instance.STATUS_STOP);
instance.failure(error);
} finally {
instance.setLock(false);
}
const currentTimestamp = new Date().getTime();
instance.startTimestamp = currentTimestamp;
instance.println("INFO", $t("start.startInstance"));
await this.sleep();
return await instance.execPreset("start", this.source);
}
}

0
src/entity/commands/stop.ts Normal file → Executable file
View File

0
src/entity/commands/task/players.ts Normal file → Executable file
View File

0
src/entity/commands/task/time.ts Normal file → Executable file
View File

0
src/entity/commands/update.ts Normal file → Executable file
View File

0
src/entity/config.ts Normal file → Executable file
View File

0
src/entity/ctx.ts Normal file → Executable file
View File

0
src/entity/instance/Instance_config.ts Normal file → Executable file
View File

0
src/entity/instance/instance.ts Normal file → Executable file
View File

0
src/entity/instance/interface.ts Normal file → Executable file
View File

0
src/entity/instance/life_cycle.ts Normal file → Executable file
View File

0
src/entity/instance/preset.ts Normal file → Executable file
View File

0
src/entity/instance/process_config.ts Normal file → Executable file
View File

0
src/entity/minecraft/mc_getplayer.ts Normal file → Executable file
View File

0
src/entity/minecraft/mc_getplayer_bedrock.ts Normal file → Executable file
View File

0
src/entity/minecraft/mc_update.ts Normal file → Executable file
View File

0
src/i18n/index.ts Normal file → Executable file
View File

0
src/i18n/language/en_us.ts Normal file → Executable file
View File

10
src/i18n/language/zh_cn.ts Normal file → Executable file
View File

@ -53,7 +53,7 @@ export default {
start: {
instanceNotDown: "实例未处于关闭状态,无法再进行启动",
instanceMaturity: "实例使用到期时间已到,无法再启动实例",
startInstance: "正在启动实例..."
startInstance: "正在准备启动实例..."
},
// src\entity\commands\general\general_restart.ts
restart: {
@ -84,8 +84,9 @@ export default {
`,
startErr: "实例启动失败,请检查启动命令,主机环境和配置文件等",
startSuccess: "实例 {{instanceUuid}} 成功启动 PID: {{pid}}.",
startOrdinaryTerminal: "应用实例已运行,终端为普通终端模式,您可以在底部的命令输入框发送命令,不支持 CtrlTab 等功能键"
startSuccess: "实例 {{instanceUuid}} 成功启动 PID: {{pid}}",
startOrdinaryTerminal:
"应用实例已运行,您可以在底部的命令输入框发送命令,如果您需要支持 CtrlTab 等快捷键等高级控制台功能,请前往终端设置开启仿真终端功能"
},
// src\entity\commands\general\general_stop.ts
general_stop: {
@ -281,8 +282,7 @@ export default {
existRepeatTask: "已存在重复的任务",
illegalName: "非法的计划名,仅支持下划线,数字,字母和部分本地语言",
crateTask: "创建计划任务 {{name}}:\n{{task}}",
crateTaskErr:
"计划任务创建错误,不正确的时间表达式: \n{{name}}: {{timeArray}}\n请尝试删除 data/TaskConfig/{{name}}.json 文件解决此问题",
crateTaskErr: "计划任务创建错误,不正确的时间表达式: \n{{name}}: {{timeArray}}\n请尝试删除 data/TaskConfig/{{name}}.json 文件解决此问题",
crateSuccess: "创建计划任务 {{name}} 完毕",
execCmdErr: "实例 {{uuid}} 计划任务 {{name}} 执行错误: \n {{error}}"
},

0
src/routers/Instance_router.ts Normal file → Executable file
View File

0
src/routers/auth_router.ts Normal file → Executable file
View File

0
src/routers/environment_router.ts Normal file → Executable file
View File

0
src/routers/file_router.ts Normal file → Executable file
View File

0
src/routers/http_router.ts Normal file → Executable file
View File

0
src/routers/info_router.ts Normal file → Executable file
View File

0
src/routers/instance_event_router.ts Normal file → Executable file
View File

0
src/routers/passport_router.ts Normal file → Executable file
View File

0
src/routers/schedule_router.ts Normal file → Executable file
View File

0
src/routers/stream_router.ts Normal file → Executable file
View File

0
src/service/docker_service.ts Normal file → Executable file
View File

0
src/service/file_router_service.ts Normal file → Executable file
View File

0
src/service/http.ts Normal file → Executable file
View File

0
src/service/install.ts Normal file → Executable file
View File

0
src/service/interfaces.ts Normal file → Executable file
View File

0
src/service/log.ts Normal file → Executable file
View File

0
src/service/mission_passport.ts Normal file → Executable file
View File

0
src/service/node_auth.ts Normal file → Executable file
View File

0
src/service/protocol.ts Normal file → Executable file
View File

0
src/service/router.ts Normal file → Executable file
View File

0
src/service/system_file.ts Normal file → Executable file
View File

0
src/service/system_instance.ts Normal file → Executable file
View File

0
src/service/system_instance_control.ts Normal file → Executable file
View File

0
src/service/ui.ts Normal file → Executable file
View File

0
src/service/version.ts Normal file → Executable file
View File

0
src/tools/filepath.ts Normal file → Executable file
View File

0
src/types/properties.d.ts vendored Normal file → Executable file
View File

0
tsconfig.json Normal file → Executable file
View File

0
webpack.config.js Normal file → Executable file
View File