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:
Hornwitser authored and GitHub committed 2024-01-18 16:10:42 +01:00
1 parent 885c18c0d4
commit 8884116ee9
15 files changed
+297 -25

No files matched your search

+21 -2
View File
@@ -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() {