mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 23:33:12 +09:00
Implement stop and restart of controller/hosts (#554)
Implement remotely initiated stopping and restarting of the controller and hosts. Restarting is implemented by exiting with a non-zero exit code and relying on a process manager to start the procress again. To prevent accidentally trying to restart on a system that doesn't have a process manager present the --can-restart command line option needs to be passed to enable the restart operation.
This commit is contained in:
1 parent
885c18c0d4
commit
8884116ee9
15 files changed
+297
-25
No files matched your search
+12
-2
@@ -94,7 +94,12 @@ async function startHost() {
|
||||
})
|
||||
.command("plugin", "Manage available plugins", lib.pluginCommand)
|
||||
.command("config", "Manage Host config", lib.configCommand)
|
||||
.command("run", "Run host")
|
||||
.command("run", "Run host", yargs => {
|
||||
yargs.option("can-restart", {
|
||||
type: "boolean", nargs: 0, default: false,
|
||||
describe: "Indicate that a process monitor will restart this host on failure",
|
||||
});
|
||||
})
|
||||
.demandCommand(1, "You need to specify a command to run")
|
||||
.strict()
|
||||
.parseSync()
|
||||
@@ -206,6 +211,7 @@ async function startHost() {
|
||||
hostConfig,
|
||||
tlsCa,
|
||||
pluginInfos,
|
||||
Boolean(args.canRestart),
|
||||
...await Host.bootstrap(hostConfig)
|
||||
);
|
||||
|
||||
@@ -295,7 +301,11 @@ ${err.stack}`
|
||||
);
|
||||
}
|
||||
|
||||
process.exitCode = 1;
|
||||
if (err instanceof lib.AuthenticationFailed) {
|
||||
process.exitCode = 8;
|
||||
} else {
|
||||
process.exitCode = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +278,12 @@ export default class Host extends lib.Link {
|
||||
hostConfig: lib.HostConfig,
|
||||
tlsCa: string | undefined,
|
||||
pluginInfos: lib.PluginNodeEnvInfo[],
|
||||
public modStore: lib.ModStore,
|
||||
/**
|
||||
* If true indicates that there is a process monitor present that
|
||||
* will restart this host on a non-zero exit codes.
|
||||
*/
|
||||
public canRestart = false,
|
||||
public modStore = new lib.ModStore(hostConfig.get("host.mods_directory"), new Map()),
|
||||
) {
|
||||
super(connector);
|
||||
this.tlsCa = tlsCa;
|
||||
@@ -345,6 +350,8 @@ export default class Host extends lib.Link {
|
||||
});
|
||||
}
|
||||
|
||||
this.handle(lib.HostStopRequest, this.handleHostStopRequest.bind(this));
|
||||
this.handle(lib.HostRestartRequest, this.handleHostRestartRequest.bind(this));
|
||||
this.handle(lib.HostConfigGetRequest, this.handleHostConfigGetRequest.bind(this));
|
||||
this.handle(lib.HostConfigSetFieldRequest, this.handleHostConfigSetFieldRequest.bind(this));
|
||||
this.handle(lib.HostConfigSetPropRequest, this.handleHostConfigSetPropRequest.bind(this));
|
||||
@@ -430,6 +437,18 @@ export default class Host extends lib.Link {
|
||||
}
|
||||
}
|
||||
|
||||
async handleHostStopRequest() {
|
||||
this.shutdown();
|
||||
}
|
||||
|
||||
async handleHostRestartRequest() {
|
||||
if (!this.canRestart) {
|
||||
throw new lib.RequestError("Cannot restart, host does not have a process monitor to restart it.");
|
||||
}
|
||||
process.exitCode = 1;
|
||||
this.shutdown();
|
||||
}
|
||||
|
||||
async handleHostConfigGetRequest() {
|
||||
return this.config.toRemote("control");
|
||||
}
|
||||
@@ -751,7 +770,7 @@ export default class Host extends lib.Link {
|
||||
}
|
||||
|
||||
async handleSystemInfoRequest() {
|
||||
return lib.gatherSystemInfo(this.config.get("host.id"));
|
||||
return lib.gatherSystemInfo(this.config.get("host.id"), this.canRestart);
|
||||
}
|
||||
|
||||
async handleHostMetricsRequest() {
|
||||
|
||||
Reference in new issue
Block a user