mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 00:23:12 +09:00
Add checks for updated version on disk
This commit is contained in:
5 files changed
+42
-1
No files matched your search
@@ -354,6 +354,8 @@ async function initialize(): Promise<InitializeParameters> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
controllerConfig.set("controller.version", version); // Allows tracking last loaded version
|
||||||
|
|
||||||
if (!controllerConfig.get("controller.auth_secret")) {
|
if (!controllerConfig.get("controller.auth_secret")) {
|
||||||
logger.info("Generating new controller authentication secret");
|
logger.info("Generating new controller authentication secret");
|
||||||
let asyncRandomBytes = util.promisify(crypto.randomBytes);
|
let asyncRandomBytes = util.promisify(crypto.randomBytes);
|
||||||
|
|||||||
@@ -523,6 +523,18 @@ export default class Controller {
|
|||||||
}
|
}
|
||||||
requests.push(hostConnection.send(new lib.SystemInfoRequest()));
|
requests.push(hostConnection.send(new lib.SystemInfoRequest()));
|
||||||
}
|
}
|
||||||
|
if (!this.config.restartRequired) {
|
||||||
|
// If a restart isn't already required, then test if a new version is installed
|
||||||
|
try {
|
||||||
|
const runningVersion = this.config.get("controller.version");
|
||||||
|
const packageJson = await fs.readJSON(path.join(__dirname, "..", "package.json"));
|
||||||
|
if (runningVersion !== packageJson.version) {
|
||||||
|
this.config.restartRequired = true;
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
logger.warn(`Failed to read package json:\n${err.stack ?? err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
requests.push(lib.gatherSystemInfo("controller", this.canRestart, this.config.restartRequired));
|
requests.push(lib.gatherSystemInfo("controller", this.canRestart, this.config.restartRequired));
|
||||||
const newMetrics = await Promise.all(requests);
|
const newMetrics = await Promise.all(requests);
|
||||||
for (const metric of newMetrics) {
|
for (const metric of newMetrics) {
|
||||||
|
|||||||
@@ -176,13 +176,14 @@ async function startHost() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hostConfig.set("host.version", version); // Allows tracking last loaded version
|
||||||
|
|
||||||
if (command === "config") {
|
if (command === "config") {
|
||||||
await lib.handleConfigCommand(args, hostConfig, args.config);
|
await lib.handleConfigCommand(args, hostConfig, args.config);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get here the command was run
|
// If we get here the command was run
|
||||||
|
|
||||||
await fs.ensureDir(hostConfig.get("host.instances_directory"));
|
await fs.ensureDir(hostConfig.get("host.instances_directory"));
|
||||||
await fs.ensureDir(hostConfig.get("host.mods_directory"));
|
await fs.ensureDir(hostConfig.get("host.mods_directory"));
|
||||||
await fs.ensureDir("modules");
|
await fs.ensureDir("modules");
|
||||||
|
|||||||
@@ -798,6 +798,18 @@ export default class Host extends lib.Link {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleSystemInfoRequest() {
|
async handleSystemInfoRequest() {
|
||||||
|
if (!this.config.restartRequired) {
|
||||||
|
// If a restart isn't already required, then test if a new version is installed
|
||||||
|
try {
|
||||||
|
const runningVersion = this.config.get("host.version");
|
||||||
|
const packageJson = await fs.readJSON(path.join(__dirname, "..", "package.json"));
|
||||||
|
if (runningVersion !== packageJson.version) {
|
||||||
|
this.config.restartRequired = true;
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
logger.warn(`Failed to read package json:\n${err.stack ?? err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
return lib.gatherSystemInfo(this.config.get("host.id"), this.canRestart, this.config.restartRequired);
|
return lib.gatherSystemInfo(this.config.get("host.id"), this.canRestart, this.config.restartRequired);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import type { PluginNodeEnvInfo, PluginWebpackEnvInfo } from "../plugin";
|
|||||||
import { Static } from "@sinclair/typebox";
|
import { Static } from "@sinclair/typebox";
|
||||||
|
|
||||||
export interface ControllerConfigFields {
|
export interface ControllerConfigFields {
|
||||||
|
"controller.version": string;
|
||||||
"controller.name": string;
|
"controller.name": string;
|
||||||
"controller.mods_directory": string;
|
"controller.mods_directory": string;
|
||||||
"controller.database_directory": string;
|
"controller.database_directory": string;
|
||||||
@@ -46,6 +47,12 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static fieldDefinitions: classes.ConfigDefs<ControllerConfigFields> = {
|
static fieldDefinitions: classes.ConfigDefs<ControllerConfigFields> = {
|
||||||
|
"controller.version": {
|
||||||
|
type: "string",
|
||||||
|
initialValue: "", // Set on start
|
||||||
|
readonly: ["controller"],
|
||||||
|
hidden: true,
|
||||||
|
},
|
||||||
"controller.name": {
|
"controller.name": {
|
||||||
title: "Name",
|
title: "Name",
|
||||||
description: "Name of the cluster.",
|
description: "Name of the cluster.",
|
||||||
@@ -215,6 +222,7 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface HostConfigFields {
|
export interface HostConfigFields {
|
||||||
|
"host.version": string;
|
||||||
"host.name": string;
|
"host.name": string;
|
||||||
"host.id": number;
|
"host.id": number;
|
||||||
"host.factorio_directory": string;
|
"host.factorio_directory": string;
|
||||||
@@ -237,6 +245,12 @@ export interface HostConfigFields {
|
|||||||
export class HostConfig extends classes.Config<HostConfigFields> {
|
export class HostConfig extends classes.Config<HostConfigFields> {
|
||||||
declare static fromJSON: (json: classes.ConfigSchema, location: classes.ConfigLocation) => HostConfig;
|
declare static fromJSON: (json: classes.ConfigSchema, location: classes.ConfigLocation) => HostConfig;
|
||||||
static fieldDefinitions: classes.ConfigDefs<HostConfigFields> = {
|
static fieldDefinitions: classes.ConfigDefs<HostConfigFields> = {
|
||||||
|
"host.version": {
|
||||||
|
type: "string",
|
||||||
|
initialValue: "", // Set on start
|
||||||
|
readonly: ["host"],
|
||||||
|
hidden: true,
|
||||||
|
},
|
||||||
"host.name": {
|
"host.name": {
|
||||||
description: "Name of the host",
|
description: "Name of the host",
|
||||||
type: "string",
|
type: "string",
|
||||||
|
|||||||
Reference in new issue
Block a user