mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 16:13:12 +09:00
Rename Ctl's usage of "control" to "ctl" (#1039)
Ctl ended up calling its main class for "Control" for historical
reasons, along with its config file and plugin entrypoint.
The plugin entrypoint was renamed to ctl in 808eda0513. This
finishes that renaming by also renaming the main class, default config
file, config-control command, and main entrypoint.
The config-control command is renamed to config to be consistent with
the host and controller's config commands.
The term "control" is still kept in the config and message locations as
a common specifier for both ctl and web_ui.
This commit is contained in:
1 parent
1d1d9bb1c4
commit
5df5af7ca8
35 files changed
+383
-383
No files matched your search
+45
-45
@@ -23,7 +23,7 @@ import { BaseCtlPlugin, CtlHooks } from "./src/BaseCtlPlugin.js";
|
||||
* Connector for control connection to controller
|
||||
* @private
|
||||
*/
|
||||
class ControlConnector extends lib.WebSocketClientConnector {
|
||||
class CtlConnector extends lib.WebSocketClientConnector {
|
||||
private _token: string;
|
||||
|
||||
constructor(url: string, maxReconnectDelay: number, token: string) {
|
||||
@@ -45,23 +45,23 @@ class ControlConnector extends lib.WebSocketClientConnector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles running the control
|
||||
* Handles running ctl
|
||||
*
|
||||
* Connects to the controller over WebSocket and sends commands to it.
|
||||
* @static
|
||||
*/
|
||||
export class Control extends lib.Link {
|
||||
/** Control config used for connecting to the controller. */
|
||||
config: lib.ControlConfig;
|
||||
export class Ctl extends lib.Link {
|
||||
/** Ctl config used for connecting to the controller. */
|
||||
config: lib.CtlConfig;
|
||||
/** Keep the control connection alive after the command completes. */
|
||||
keepOpen = false;
|
||||
|
||||
constructor(
|
||||
connector: ControlConnector,
|
||||
controlConfig: lib.ControlConfig,
|
||||
connector: CtlConnector,
|
||||
ctlConfig: lib.CtlConfig,
|
||||
) {
|
||||
super(connector);
|
||||
this.config = controlConfig;
|
||||
this.config = ctlConfig;
|
||||
|
||||
this.handle(lib.LogMessageEvent, this.handleLogMessageEvent.bind(this));
|
||||
this.handle(lib.DebugWsMessageEvent, this.handleDebugWsMessageEvent.bind(this));
|
||||
@@ -92,7 +92,7 @@ export class Control extends lib.Link {
|
||||
|
||||
async shutdown() {
|
||||
try {
|
||||
await (this.connector as ControlConnector).disconnect();
|
||||
await (this.connector as CtlConnector).disconnect();
|
||||
} catch (err) {
|
||||
if (!(err instanceof lib.SessionLost)) {
|
||||
throw err;
|
||||
@@ -135,7 +135,7 @@ interface InitializeParameters {
|
||||
shouldRun: boolean;
|
||||
ctlHooks: CtlHooks;
|
||||
rootCommands?: lib.CommandTree;
|
||||
controlConfig?: lib.ControlConfig;
|
||||
ctlConfig?: lib.CtlConfig;
|
||||
}
|
||||
|
||||
export async function initialize(
|
||||
@@ -166,7 +166,7 @@ export async function initialize(
|
||||
.option("config", {
|
||||
nargs: 1,
|
||||
describe: "config file to get credentails from",
|
||||
default: "config-control.json",
|
||||
default: "config-ctl.json",
|
||||
defaultDescription: "auto",
|
||||
type: "string",
|
||||
})
|
||||
@@ -178,7 +178,7 @@ export async function initialize(
|
||||
})
|
||||
.option("bypass-lock-file", { hidden: true, type: "boolean", nargs: 0, default: false })
|
||||
.command("plugin", "Manage available plugins", lib.pluginCommand)
|
||||
.command("control-config", "Manage Control config", lib.configCommand)
|
||||
.command("config", "Manage ctl config", lib.configCommand)
|
||||
.wrap(parser.terminalWidth())
|
||||
.help(false) // Disable help to avoid triggering it on the first parse.
|
||||
;
|
||||
@@ -222,22 +222,22 @@ export async function initialize(
|
||||
.parse(argv) as CtlArguments
|
||||
;
|
||||
|
||||
const controlConfigPath = args.config;
|
||||
const controlConfigLockPath = `${controlConfigPath}.lock`;
|
||||
const ctlConfigPath = args.config;
|
||||
const ctlConfigLockPath = `${ctlConfigPath}.lock`;
|
||||
if (args.bypassLockFile) {
|
||||
await fs.unlink(controlConfigLockPath).catch(() => {}); // ignore error, file might not exist
|
||||
await fs.unlink(ctlConfigLockPath).catch(() => {}); // ignore error, file might not exist
|
||||
}
|
||||
|
||||
let controlConfig;
|
||||
const controlConfigLock = new lib.LockFile(controlConfigLockPath);
|
||||
logger.verbose(`Loading config from ${controlConfigPath}`);
|
||||
let ctlConfig;
|
||||
const ctlConfigLock = new lib.LockFile(ctlConfigLockPath);
|
||||
logger.verbose(`Loading config from ${ctlConfigPath}`);
|
||||
try {
|
||||
controlConfig = await lib.ControlConfig.fromFile("control", controlConfigPath);
|
||||
ctlConfig = await lib.CtlConfig.fromFile("control", ctlConfigPath);
|
||||
|
||||
} catch (err: any) {
|
||||
if (err.code === "ENOENT") {
|
||||
logger.verbose("Config not found, initializing new config");
|
||||
controlConfig = new lib.ControlConfig("control", undefined, controlConfigPath);
|
||||
ctlConfig = new lib.CtlConfig("control", undefined, ctlConfigPath);
|
||||
|
||||
} else {
|
||||
throw new lib.StartupError(`Failed to load ${args.config}: ${err.stack ?? err.message ?? err}`);
|
||||
@@ -249,13 +249,13 @@ export async function initialize(
|
||||
parser.exit(1, undefined as unknown as Error); // Type definition file is wrong.
|
||||
}
|
||||
|
||||
// Handle the control-config command before trying to connect.
|
||||
if (args._[0] === "control-config") {
|
||||
await lib.handleConfigCommand(args, controlConfig, controlConfigLock);
|
||||
return { args, controlConfig, ctlHooks, rootCommands, shouldRun: false };
|
||||
// Handle the config command before trying to connect.
|
||||
if (args._[0] === "config") {
|
||||
await lib.handleConfigCommand(args, ctlConfig, ctlConfigLock);
|
||||
return { args, ctlConfig, ctlHooks, rootCommands, shouldRun: false };
|
||||
}
|
||||
|
||||
return { args, controlConfig, ctlHooks, rootCommands, shouldRun: true };
|
||||
return { args, ctlConfig, ctlHooks, rootCommands, shouldRun: true };
|
||||
}
|
||||
|
||||
export function selectTargetCommand(args: CtlArguments, rootCommands: lib.CommandTree): lib.Command {
|
||||
@@ -268,30 +268,30 @@ export function selectTargetCommand(args: CtlArguments, rootCommands: lib.Comman
|
||||
return targetCommand;
|
||||
}
|
||||
|
||||
async function startControl() {
|
||||
async function startCtl() {
|
||||
const {
|
||||
args,
|
||||
shouldRun,
|
||||
rootCommands,
|
||||
controlConfig,
|
||||
ctlConfig,
|
||||
} = await initialize(process.argv.slice(2));
|
||||
if (!shouldRun || !rootCommands || !controlConfig) {
|
||||
if (!shouldRun || !rootCommands || !ctlConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!controlConfig.get("control.controller_url") || !controlConfig.get("control.controller_token")) {
|
||||
if (!ctlConfig.get("ctl.controller_url") || !ctlConfig.get("ctl.controller_token")) {
|
||||
logger.error("Missing URL and/or token to connect with. See README.md for setting up access.");
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
let controlConnector = new ControlConnector(
|
||||
controlConfig.get("control.controller_url")!,
|
||||
controlConfig.get("control.max_reconnect_delay"),
|
||||
controlConfig.get("control.controller_token")!,
|
||||
let controlConnector = new CtlConnector(
|
||||
ctlConfig.get("ctl.controller_url")!,
|
||||
ctlConfig.get("ctl.max_reconnect_delay"),
|
||||
ctlConfig.get("ctl.controller_token")!,
|
||||
);
|
||||
|
||||
let control = new Control(controlConnector, controlConfig);
|
||||
let ctl = new Ctl(controlConnector, ctlConfig);
|
||||
try {
|
||||
await controlConnector.connect();
|
||||
} catch (err) {
|
||||
@@ -302,15 +302,15 @@ async function startControl() {
|
||||
}
|
||||
|
||||
// Handle interrupts
|
||||
process.on("SIGINT", lib.createShutdownGuard(logger, "interrupt", control.shutdown.bind(control)));
|
||||
process.on("SIGTERM", lib.createShutdownGuard(logger, "termination", control.shutdown.bind(control)));
|
||||
process.on("SIGINT", lib.createShutdownGuard(logger, "interrupt", ctl.shutdown.bind(ctl)));
|
||||
process.on("SIGTERM", lib.createShutdownGuard(logger, "termination", ctl.shutdown.bind(ctl)));
|
||||
|
||||
try {
|
||||
const targetCommand = selectTargetCommand(args, rootCommands);
|
||||
await targetCommand.run(args, control);
|
||||
await targetCommand.run(args, ctl);
|
||||
|
||||
} catch (err) {
|
||||
control.keepOpen = false;
|
||||
ctl.keepOpen = false;
|
||||
if (err instanceof lib.CommandError) {
|
||||
logger.error(`Error running command: ${err.message}`);
|
||||
process.exitCode = 1;
|
||||
@@ -328,8 +328,8 @@ async function startControl() {
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (!control.keepOpen) {
|
||||
await control.shutdown();
|
||||
if (!ctl.keepOpen) {
|
||||
await ctl.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -343,16 +343,16 @@ I version of clusterio. Expect things to break. I
|
||||
+==========================================================+
|
||||
`
|
||||
);
|
||||
startControl().catch(err => {
|
||||
startCtl().catch(err => {
|
||||
if (err.errors) {
|
||||
logger.fatal(JSON.stringify(err.errors, null, "\t"));
|
||||
}
|
||||
if (!(err instanceof lib.StartupError)) {
|
||||
logger.fatal(`
|
||||
+------------------------------------------------------------+
|
||||
| Unexpected error occured while starting control, please |
|
||||
| report it to https://github.com/clusterio/clusterio/issues |
|
||||
+------------------------------------------------------------+
|
||||
+---------------------------------------------------------------+
|
||||
| Unexpected error occured while starting clussterioctl, please |
|
||||
| report it to https://github.com/clusterio/clusterio/issues |
|
||||
+---------------------------------------------------------------+
|
||||
${err.stack}`
|
||||
);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user