Add auto_start config option to instances

Add option to automatically start the instance on slave startup.
This commit is contained in:
Hornwitser committed 2020-11-17 04:34:49 +01:00
1 parent 9d2ac2b81f
commit 87da492ef8
3 files changed
+28

No files matched your search

+1
View File
@@ -48,6 +48,7 @@ Version 2.0.0
Clusterio core. Previously this was handled by the playerManager plugin.
- Added stripping of long paths in the Factorio server log.
- Added option to configure maximum number of commands to send in parallel.
- Added option to auto start instances on slave startup.
### Changes
+6
View File
@@ -196,6 +196,12 @@ InstanceGroup.define({
type: "number",
optional: true,
});
InstanceGroup.define({
name: "auto_start",
description: "Automatically start this instance when the slave hosting it is started up",
type: "boolean",
initial_value: false,
});
InstanceGroup.finalize();
/**
+21
View File
@@ -924,6 +924,7 @@ class Slave extends libLink.Link {
this.serverPlugins = new Map(Object.entries(data.plugins));
});
this._startup = true;
this._disconnecting = false;
this._shuttingDown = false;
@@ -1296,6 +1297,26 @@ class Slave extends libLink.Link {
});
}
await libLink.messages.updateInstances.send(this, { instances: list });
// Handle configured auto startup instances
if (this._startup) {
this._startup = false;
for (let [instanceId, instanceInfo] of this.instanceInfos) {
if (instanceInfo.config.get("instance.auto_start")) {
try {
let instanceConnection = await this._connectInstance(instanceId);
await libLink.messages.startInstance.send(instanceConnection, {
instance_id: instanceId,
save: null,
});
} catch (err) {
console.error(`Error during auto startup for ${instanceInfo.config.get("instance.name")}:`);
console.error(err);
}
}
}
}
}
async prepareDisconnectRequestHandler(message, request) {