Don't require reboot if setting fan control

Signed-off-by: Christina Ying Wang <christina@balena.io>
This commit is contained in:
Christina Ying Wang 2024-11-12 22:10:00 -08:00
parent 828bd22ba0
commit 2f2b2e1c50
3 changed files with 22 additions and 2 deletions

View File

@ -41,6 +41,12 @@ export abstract class ConfigBackend {
// Example an empty string should return null.
public abstract createConfigVarName(configName: string): string | null;
// Is a reboot required for the given config options?
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async isRebootRequired(_opts: ConfigOptions): Promise<boolean> {
return true;
}
// Allow a chosen config backend to be initialised
public async initialise(): Promise<ConfigBackend> {
return this;

View File

@ -1,6 +1,7 @@
import { isRight } from 'fp-ts/lib/Either';
import Reporter from 'io-ts-reporters';
import * as t from 'io-ts';
import * as _ from 'lodash';
import { ConfigBackend } from './backend';
import type { ConfigOptions } from './backend';
@ -145,6 +146,16 @@ export class PowerFanConfig extends ConfigBackend {
return PowerFanConfig.CONFIGS.has(PowerFanConfig.stripPrefix(envVar));
}
public async isRebootRequired(opts: ConfigOptions): Promise<boolean> {
const supportedOpts = _.pickBy(
_.mapKeys(opts, (_value, key) => PowerFanConfig.stripPrefix(key)),
(_value, key) => this.isSupportedConfig(key),
);
const current = await this.getBootConfig();
// A reboot is only required if the power mode is changing
return current.power_mode !== supportedOpts.power_mode;
}
public processConfigVarName(envVar: string): string {
return PowerFanConfig.stripPrefix(envVar).toLowerCase();
}

View File

@ -529,18 +529,21 @@ async function getBackendSteps(
const { deviceType } = await config.getMany(['deviceType']);
// Check for required bootConfig changes
let rebootRequired = false;
for (const backend of backends) {
if (changeRequired(backend, current, target, deviceType)) {
steps.push({
action: 'setBootConfig',
target,
});
rebootRequired =
(await backend.isRebootRequired(target)) || rebootRequired;
}
}
return [
// All backend steps require a reboot
...(steps.length > 0
// All backend steps require a reboot except fan control
...(steps.length > 0 && rebootRequired
? [{ action: 'setRebootBreadcrumb' } as ConfigStep]
: []),
...steps,