mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-18 13:26:24 +00:00
device update
: Use detached HUP for os updates
This will not track HUP progress when we call OS update in the CLI but will allow for more reliable OS updates by default. Change-type: major
This commit is contained in:
parent
d023d0af91
commit
4b3fdcf99c
@ -146,7 +146,18 @@ export default class DeviceOsUpdateCmd extends Command {
|
||||
'Host OS updates require a device restart when they complete. Are you sure you want to proceed?',
|
||||
);
|
||||
|
||||
await sdk.models.device.startOsUpdate(uuid, targetOsVersion);
|
||||
await patterns.awaitDeviceOsUpdate(uuid, targetOsVersion);
|
||||
await sdk.models.device
|
||||
.startOsUpdate(uuid, targetOsVersion, {
|
||||
runDetached: true,
|
||||
})
|
||||
.then(() => {
|
||||
console.log(
|
||||
`The balena OS update has started. You can keep track of the progress via the dashboard.\n` +
|
||||
`To open the dashboard page related to a device via the CLI, you can use \`balena device UUID --view\``,
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(`Failed to start OS update for device ${uuid}:`, error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,8 @@ import {
|
||||
ExpectedError,
|
||||
NotAvailableInOfflineModeError,
|
||||
} from '../errors';
|
||||
import { getBalenaSdk, getVisuals, stripIndent, getCliForm } from './lazy';
|
||||
import { getBalenaSdk, stripIndent, getCliForm } from './lazy';
|
||||
import validation = require('./validation');
|
||||
import { delay } from './helpers';
|
||||
|
||||
export function authenticate(options: object): Promise<void> {
|
||||
const balena = getBalenaSdk();
|
||||
@ -286,51 +285,6 @@ export async function getAndSelectOrganization() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function awaitDeviceOsUpdate(
|
||||
uuid: string,
|
||||
targetOsVersion: string,
|
||||
) {
|
||||
const balena = getBalenaSdk();
|
||||
|
||||
const deviceName = await balena.models.device.getName(uuid);
|
||||
const visuals = getVisuals();
|
||||
const progressBar = new visuals.Progress(
|
||||
`Updating the OS of ${deviceName} to v${targetOsVersion}`,
|
||||
);
|
||||
progressBar.update({ percentage: 0 });
|
||||
|
||||
const poll = async (): Promise<void> => {
|
||||
const [osUpdateStatus, { overall_progress: osUpdateProgress }] =
|
||||
await Promise.all([
|
||||
balena.models.device.getOsUpdateStatus(uuid),
|
||||
balena.models.device.get(uuid, { $select: 'overall_progress' }),
|
||||
]);
|
||||
if (osUpdateStatus.status === 'done') {
|
||||
console.info(
|
||||
`The device ${deviceName} has been updated to v${targetOsVersion} and will restart shortly!`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (osUpdateStatus.error) {
|
||||
throw new ExpectedError(
|
||||
`Failed to complete Host OS update on device ${deviceName}\n${osUpdateStatus.error}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (osUpdateProgress !== null) {
|
||||
// Avoid resetting to 0% at end of process when device goes disconnected.
|
||||
progressBar.update({ percentage: osUpdateProgress });
|
||||
}
|
||||
|
||||
await delay(3000);
|
||||
await poll();
|
||||
};
|
||||
|
||||
await poll();
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/*
|
||||
* Given fleetOrDevice, which may be
|
||||
* - a fleet name
|
||||
|
Loading…
Reference in New Issue
Block a user