MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / exec

Function exec

daemon/src/entity/commands/start.ts:20–91  ·  view source on GitHub ↗
(instance: Instance)

Source from the content-addressed store, hash-verified

18 }
19
20 async exec(instance: Instance) {
21 if (instance.status() !== Instance.STATUS_STOP)
22 return instance.failure(new StartupError($t("TXT_CODE_start.instanceNotDown")));
23
24 // Create the instance directory if it doesn't exist
25 if (!fs.existsSync(instance.absoluteCwdPath())) {
26 await fs.mkdirs(instance.absoluteCwdPath());
27 }
28
29 try {
30 instance.setLock(true);
31 instance.status(Instance.STATUS_STARTING);
32 instance.startCount++;
33
34 instance.startTimestamp = Date.now();
35
36 if (instance.config.endTime) {
37 const endTime = instance.config.endTime;
38 if (endTime) {
39 if (endTime <= instance.startTimestamp) {
40 throw new Error($t("TXT_CODE_start.instanceMaturity"));
41 }
42 }
43 }
44
45 instance.println("INFO", $t("TXT_CODE_start.startInstance"));
46
47 // prevent the dead-loop from starting
48 await this.sleep();
49
50 // check the disk space
51 if (instance.config.docker?.maxSpace && instance.config.docker.maxSpace > 0) {
52 instance.println("INFO", $t("TXT_CODE_2d7b8a91"));
53 const result = await disk_limit_service.checkDiskNow(
54 {
55 instance,
56 workspace: instance.absoluteCwdPath(),
57 maxSpace: instance.config.docker.maxSpace
58 },
59 false
60 );
61 if (result?.isFull) {
62 throw new StartupError(
63 $t(
64 "TXT_CODE_e5938389",
65 {
66 storageLimit: result?.storageLimit,
67 storageUsage: result?.storageUsage
68 }
69 )
70 );
71 } else {
72 instance.println(
73 "INFO",
74 $t("TXT_CODE_85e29331", {
75 storageUsage: result?.storageUsage,
76 storageLimit: result?.storageLimit
77 })

Callers

nothing calls this directly

Calls 10

$tFunction · 0.90
failureMethod · 0.80
absoluteCwdPathMethod · 0.80
setLockMethod · 0.80
printlnMethod · 0.80
checkDiskNowMethod · 0.80
releaseResourcesMethod · 0.80
statusMethod · 0.65
createProcessMethod · 0.45
execPresetMethod · 0.45

Tested by

no test coverage detected