From a111d8dcc40452df5c67198a47346b22fec53ee7 Mon Sep 17 00:00:00 2001 From: jaomaloy Date: Mon, 21 Oct 2024 21:06:02 +0800 Subject: [PATCH] [os-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 --- src/commands/device/os-update.ts | 5 ++-- src/utils/patterns.ts | 48 +------------------------------- 2 files changed, 4 insertions(+), 49 deletions(-) diff --git a/src/commands/device/os-update.ts b/src/commands/device/os-update.ts index 580d2eefec..841014ed1c 100644 --- a/src/commands/device/os-update.ts +++ b/src/commands/device/os-update.ts @@ -146,7 +146,8 @@ 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, + }); } } diff --git a/src/utils/patterns.ts b/src/utils/patterns.ts index 1ea2cafd3a..b13ba8fd5c 100644 --- a/src/utils/patterns.ts +++ b/src/utils/patterns.ts @@ -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 { 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 => { - 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