Skip to content

Commit

Permalink
Don't require reboot if setting fan control
Browse files Browse the repository at this point in the history
Signed-off-by: Christina Ying Wang <christina@balena.io>
  • Loading branch information
cywang117 committed Nov 14, 2024
1 parent 7f93580 commit e699a2f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/config/backends/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/config/backends/power-fan.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -158,6 +159,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();
}
Expand Down
7 changes: 5 additions & 2 deletions src/device-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e699a2f

Please sign in to comment.