mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 15: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
@@ -3,6 +3,22 @@ import { JsonString, StringEnum, plainJson } from "./composites";
|
||||
import { levels } from "../logging";
|
||||
import { ControllerConfig, HostConfig } from "../config";
|
||||
|
||||
export class ControllerStopRequest {
|
||||
declare ["constructor"]: typeof ControllerStopRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = "controller" as const;
|
||||
static permission = "core.controller.stop" as const;
|
||||
}
|
||||
|
||||
export class ControllerRestartRequest {
|
||||
declare ["constructor"]: typeof ControllerRestartRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = "controller" as const;
|
||||
static permission = "core.controller.restart" as const;
|
||||
}
|
||||
|
||||
export class ControllerConfigGetRequest {
|
||||
declare ["constructor"]: typeof ControllerConfigGetRequest;
|
||||
static type = "request" as const;
|
||||
@@ -221,6 +237,7 @@ export class SystemInfo {
|
||||
public memoryAvailable: number,
|
||||
public diskCapacity: number,
|
||||
public diskAvailable: number,
|
||||
public canRestart: boolean,
|
||||
/** Millisecond Unix timestamp this entry was last updated at */
|
||||
public updatedAt: number,
|
||||
public isDeleted: boolean,
|
||||
@@ -238,6 +255,7 @@ export class SystemInfo {
|
||||
"memoryAvailable": Type.Number(),
|
||||
"diskCapacity": Type.Number(),
|
||||
"diskAvailable": Type.Number(),
|
||||
"canRestart": Type.Boolean(),
|
||||
"updatedAt": Type.Number(),
|
||||
"isDeleted": Type.Boolean(),
|
||||
});
|
||||
@@ -255,6 +273,7 @@ export class SystemInfo {
|
||||
json.memoryAvailable,
|
||||
json.diskCapacity,
|
||||
json.diskAvailable,
|
||||
json.canRestart,
|
||||
json.updatedAt,
|
||||
json.isDeleted,
|
||||
);
|
||||
|
||||
@@ -3,6 +3,22 @@ import { jsonArray, plainJson, StringEnum } from "./composites";
|
||||
import { CollectorResultSerialized } from "../prometheus";
|
||||
import { HostConfig } from "../config/definitions";
|
||||
|
||||
export class HostStopRequest {
|
||||
declare ["constructor"]: typeof HostStopRequest;
|
||||
static type = "request" as const;
|
||||
static src = ["control", "controller"] as const;
|
||||
static dst = "host" as const;
|
||||
static permission = "core.host.stop" as const;
|
||||
}
|
||||
|
||||
export class HostRestartRequest {
|
||||
declare ["constructor"]: typeof HostRestartRequest;
|
||||
static type = "request" as const;
|
||||
static src = ["control", "controller"] as const;
|
||||
static dst = "host" as const;
|
||||
static permission = "core.host.restart" as const;
|
||||
}
|
||||
|
||||
export class HostConfigGetRequest {
|
||||
declare ["constructor"]: typeof HostConfigGetRequest;
|
||||
static type = "request" as const;
|
||||
|
||||
@@ -17,6 +17,8 @@ export const dataClasses: (RequestClass<unknown, unknown> | EventClass<unknown>)
|
||||
core.PingRequest,
|
||||
core.AccountUpdateEvent,
|
||||
|
||||
controller.ControllerStopRequest,
|
||||
controller.ControllerRestartRequest,
|
||||
controller.ControllerConfigGetRequest,
|
||||
controller.ControllerConfigSetFieldRequest,
|
||||
controller.ControllerConfigSetPropRequest,
|
||||
@@ -32,6 +34,8 @@ export const dataClasses: (RequestClass<unknown, unknown> | EventClass<unknown>)
|
||||
|
||||
subscriptions.SubscriptionRequest,
|
||||
|
||||
host.HostStopRequest,
|
||||
host.HostRestartRequest,
|
||||
host.HostConfigGetRequest,
|
||||
host.HostConfigSetFieldRequest,
|
||||
host.HostConfigSetPropRequest,
|
||||
|
||||
@@ -119,6 +119,18 @@ definePermission({
|
||||
grantByDefault: true,
|
||||
});
|
||||
|
||||
definePermission({
|
||||
name: "core.controller.stop",
|
||||
title: "Stop controller",
|
||||
description:
|
||||
"Stop the Node.js controller process making the cluster inoperable until someone with access to the system " +
|
||||
"it runs on manually starts it again.",
|
||||
});
|
||||
definePermission({
|
||||
name: "core.controller.restart",
|
||||
title: "Restart controller",
|
||||
description: "Restart the Node.js controller process if the system is set up for restarting.",
|
||||
});
|
||||
definePermission({
|
||||
name: "core.controller.get_config",
|
||||
title: "Get controller config",
|
||||
@@ -136,6 +148,18 @@ definePermission({
|
||||
"Subscribe to be notified when the system info detailing system specific information along with metrics " +
|
||||
"such as cpu, memory and disk usage for the controller and hosts are updated.",
|
||||
});
|
||||
definePermission({
|
||||
name: "core.host.stop",
|
||||
title: "Stop Hosts",
|
||||
description:
|
||||
"Stop Node.js host processes making the host inaccessible until someone with access to the system " +
|
||||
"it runs on manually starts it again.",
|
||||
});
|
||||
definePermission({
|
||||
name: "core.host.restart",
|
||||
title: "Restart Hosts",
|
||||
description: "Restart Node.js host processes if the system they run on are set up for restarting.",
|
||||
});
|
||||
definePermission({
|
||||
name: "core.host.get_config",
|
||||
title: "Get host configs",
|
||||
|
||||
@@ -134,7 +134,7 @@ function minZip<T>(a: T[], b: T[]): [T, T][] {
|
||||
|
||||
let previousTotalCpuMs: number[] = [];
|
||||
let previousIdleCpuMs: number[] = [];
|
||||
export async function gatherSystemInfo(id: SystemInfo["id"]) {
|
||||
export async function gatherSystemInfo(id: SystemInfo["id"], canRestart: boolean) {
|
||||
const cpus = os.cpus();
|
||||
const currentTotalCpuMs = cpus.map(({ times }) => times.user + times.idle + times.irq + times.nice + times.sys);
|
||||
const currentIdleCpuMs = cpus.map(({ times }) => times.idle);
|
||||
@@ -164,6 +164,7 @@ export async function gatherSystemInfo(id: SystemInfo["id"]) {
|
||||
os.freemem(),
|
||||
diskCapacity,
|
||||
diskAvailable,
|
||||
canRestart,
|
||||
Date.now(),
|
||||
false,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user