mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 15:43:13 +09:00
Pair hosts when they start instead of in the installer
The installer only writes the controller URL and host name. Running the host requests to join the cluster if it has not been approved yet, or if the controller no longer accepts its token, and waits until an admin approves it. Once approved it saves its id and token and starts as normal. A rejected host exits with code 8. clusteriohost run --user-token approves the host right away with the token of a user allowed to approve hosts. The token is not saved. This moves the pairing client into the host package, where it uses the same certificate setup as the host's connection to the controller, and removes --no-pair and the rerun handling from the installer.
This commit is contained in:
25 files changed
+948
-1131
No files matched your search
+34
-12
@@ -25,6 +25,7 @@ import { ConsoleTransport, levels, logger } from "@clusterio/lib";
|
||||
|
||||
import Host from "./src/Host.js";
|
||||
import { createScenarioCommand, handleCreateScenarioCommand } from "./src/create_scenario.js";
|
||||
import { PairingError, ensurePaired } from "./src/pairing.js";
|
||||
|
||||
let host: Host | undefined;
|
||||
|
||||
@@ -134,6 +135,10 @@ async function startHost() {
|
||||
type: "boolean", nargs: 0, default: false,
|
||||
describe: "Start the host in recovery mode with all plugins disabled and controller disconnected",
|
||||
});
|
||||
yargs.option("user-token", {
|
||||
type: "string", nargs: 1,
|
||||
describe: "Token of a user allowed to approve hosts, approves this host without waiting. Not saved",
|
||||
});
|
||||
})
|
||||
.demandCommand(1, "You need to specify a command to run")
|
||||
.strict()
|
||||
@@ -212,18 +217,6 @@ async function startHost() {
|
||||
// and as the process name in ps/top on linux.
|
||||
process.title = "clusteriohost";
|
||||
|
||||
// make sure we have the controller access token
|
||||
if (hostConfig.get("host.controller_token") === "enter token here") {
|
||||
logger.fatal("ERROR invalid config!");
|
||||
logger.fatal(
|
||||
"This host has not been set up to connect to a controller. Run the installer\n"+
|
||||
"again in this directory with npm init @clusterio and approve the host in the\n"+
|
||||
"web interface."
|
||||
);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure url ends with /
|
||||
if (!hostConfig.get("host.controller_url").endsWith("/")) {
|
||||
logger.fatal("ERROR invalid config!");
|
||||
@@ -232,6 +225,35 @@ async function startHost() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.recovery) {
|
||||
const abort = new AbortController();
|
||||
const onSignal = () => { abort.abort(); };
|
||||
process.on("SIGINT", onSignal);
|
||||
process.on("SIGTERM", onSignal);
|
||||
try {
|
||||
await ensurePaired(hostConfig, {
|
||||
version: packageConfig.version,
|
||||
userToken: args.userToken as string | undefined,
|
||||
signal: abort.signal,
|
||||
});
|
||||
} catch (err: any) {
|
||||
if (abort.signal.aborted) {
|
||||
logger.info("Stopped waiting for approval");
|
||||
return;
|
||||
}
|
||||
if (err instanceof PairingError) {
|
||||
logger.fatal(`Unable to join the cluster: ${err.message}`);
|
||||
// Exit code 8 stops the run scripts from restarting the host.
|
||||
process.exitCode = err.status === 403 ? 8 : 1;
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
} finally {
|
||||
process.off("SIGINT", onSignal);
|
||||
process.off("SIGTERM", onSignal);
|
||||
}
|
||||
}
|
||||
|
||||
let hostConnector = new HostConnector(hostConfig, pluginInfos);
|
||||
host = await Host.fromConfig(
|
||||
hostConfig,
|
||||
|
||||
Reference in new issue
Block a user