diff --git a/container-runtime/package-lock.json b/container-runtime/package-lock.json index f0cc3e788..0538c8b51 100644 --- a/container-runtime/package-lock.json +++ b/container-runtime/package-lock.json @@ -37,7 +37,7 @@ }, "../sdk/dist": { "name": "@start9labs/start-sdk", - "version": "0.3.6-beta.4", + "version": "0.4.0-beta.6", "license": "MIT", "dependencies": { "@iarna/toml": "^2.2.5", diff --git a/core/startos/src/diagnostic.rs b/core/startos/src/diagnostic.rs index 73ef93125..92733c972 100644 --- a/core/startos/src/diagnostic.rs +++ b/core/startos/src/diagnostic.rs @@ -8,9 +8,10 @@ use rpc_toolkit::{ use crate::context::{CliContext, DiagnosticContext, RpcContext}; use crate::init::SYSTEM_REBUILD_PATH; +use crate::prelude::*; use crate::shutdown::Shutdown; use crate::util::io::delete_file; -use crate::{Error, DATA_DIR}; +use crate::DATA_DIR; pub fn diagnostic() -> ParentHandler { ParentHandler::new() @@ -74,7 +75,8 @@ pub fn restart(ctx: DiagnosticContext) -> Result<(), Error> { .map(|guid| (guid, Path::new(DATA_DIR).to_owned())), restart: true, }) - .expect("receiver dropped"); + .map_err(|_| eyre!("receiver dropped")) + .log_err(); Ok(()) } pub async fn rebuild(ctx: DiagnosticContext) -> Result<(), Error> { diff --git a/core/startos/src/shutdown.rs b/core/startos/src/shutdown.rs index 12deff743..a54ccd057 100644 --- a/core/startos/src/shutdown.rs +++ b/core/startos/src/shutdown.rs @@ -91,8 +91,8 @@ pub async fn shutdown(ctx: RpcContext) -> Result<(), Error> { export_args: Some((ctx.disk_guid.clone(), Path::new(DATA_DIR).to_owned())), restart: false, })) - .map_err(|_| ()) - .expect("receiver dropped"); + .map_err(|_| eyre!("receiver dropped")) + .log_err(); Ok(()) } @@ -112,8 +112,8 @@ pub async fn restart(ctx: RpcContext) -> Result<(), Error> { export_args: Some((ctx.disk_guid.clone(), Path::new(DATA_DIR).to_owned())), restart: true, })) - .map_err(|_| ()) - .expect("receiver dropped"); + .map_err(|_| eyre!("receiver dropped")) + .log_err(); Ok(()) } diff --git a/sdk/package/lib/StartSdk.ts b/sdk/package/lib/StartSdk.ts index 2fb1e40ad..6dbafae57 100644 --- a/sdk/package/lib/StartSdk.ts +++ b/sdk/package/lib/StartSdk.ts @@ -298,23 +298,6 @@ export class StartSdk { nullIfEmpty, useEntrypoint: (overrideCmd?: string[]) => new T.UseEntrypoint(overrideCmd), - runCommand: async ( - effects: Effects, - image: { - imageId: keyof Manifest["images"] & T.ImageId - sharedRun?: boolean - }, - command: T.CommandType, - options: CommandOptions & { - mounts: Mounts | null - }, - /** - * A name to use to refer to the ephemeral subcontainer for debugging purposes - */ - name?: string, - ): Promise<{ stdout: string | Buffer; stderr: string | Buffer }> => { - return runCommand(effects, image, command, options, name) - }, /** * @description Use this class to create an Action. By convention, each Action should receive its own file. * @@ -785,13 +768,13 @@ export class StartSdk { return SubContainer.of(effects, image, mounts, name) }, /** - * @description Create a new SubContainer + * @description Run a function with a temporary SubContainer * @param effects * @param image - what container image to use * @param mounts - what to mount to the subcontainer * @param name - a name to use to refer to the ephemeral subcontainer for debugging purposes */ - with( + withTemp( effects: T.Effects, image: { imageId: T.ImageId & keyof Manifest["images"] @@ -801,7 +784,7 @@ export class StartSdk { name: string, fn: (subContainer: SubContainer) => Promise, ): Promise { - return SubContainer.with(effects, image, mounts, name, fn) + return SubContainer.withTemp(effects, image, mounts, name, fn) }, }, List: { @@ -1194,7 +1177,7 @@ export async function runCommand( commands = imageMeta.entrypoint ?? [] commands.concat(...(command.overridCmd ?? imageMeta.cmd ?? [])) } else commands = splitCommand(command) - return SubContainer.with( + return SubContainer.withTemp( effects, image, options.mounts, diff --git a/sdk/package/lib/backup/Backups.ts b/sdk/package/lib/backup/Backups.ts index 18fcbe795..fe525f2fb 100644 --- a/sdk/package/lib/backup/Backups.ts +++ b/sdk/package/lib/backup/Backups.ts @@ -76,6 +76,26 @@ export class Backups { return this } + setPreBackup(fn: (effects: BackupEffects) => Promise) { + this.preBackup = fn + return this + } + + setPostBackup(fn: (effects: BackupEffects) => Promise) { + this.postBackup = fn + return this + } + + setPreRestore(fn: (effects: BackupEffects) => Promise) { + this.preRestore = fn + return this + } + + setPostRestore(fn: (effects: BackupEffects) => Promise) { + this.postRestore = fn + return this + } + addVolume( volume: M["volumes"][number], options?: Partial<{ @@ -128,6 +148,7 @@ export class Backups { } async restoreBackup(effects: T.Effects) { + this.preRestore(effects as BackupEffects) const store = await fs .readFile("/media/startos/backup/store.json", { encoding: "utf-8", @@ -150,13 +171,14 @@ export class Backups { }, }) await rsyncResults.wait() - const dataVersion = await fs - .readFile("/media/startos/backup/dataVersion.txt", { - encoding: "utf-8", - }) - .catch((_) => null) - if (dataVersion) await effects.setDataVersion({ version: dataVersion }) } + const dataVersion = await fs + .readFile("/media/startos/backup/dataVersion.txt", { + encoding: "utf-8", + }) + .catch((_) => null) + if (dataVersion) await effects.setDataVersion({ version: dataVersion }) + this.postRestore(effects as BackupEffects) return } } diff --git a/sdk/package/lib/util/SubContainer.ts b/sdk/package/lib/util/SubContainer.ts index 69159b90b..0ec5478d2 100644 --- a/sdk/package/lib/util/SubContainer.ts +++ b/sdk/package/lib/util/SubContainer.ts @@ -149,7 +149,7 @@ export class SubContainer< } } - static async with< + static async withTemp< Manifest extends T.SDKManifest, T, Effects extends T.Effects, diff --git a/sdk/package/package-lock.json b/sdk/package/package-lock.json index aed7cd268..91aafc55b 100644 --- a/sdk/package/package-lock.json +++ b/sdk/package/package-lock.json @@ -1,12 +1,12 @@ { "name": "@start9labs/start-sdk", - "version": "0.4.0-beta.5", + "version": "0.4.0-beta.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@start9labs/start-sdk", - "version": "0.4.0-beta.5", + "version": "0.4.0-beta.6", "license": "MIT", "dependencies": { "@iarna/toml": "^3.0.0", diff --git a/sdk/package/package.json b/sdk/package/package.json index b46527df6..2c361f7f0 100644 --- a/sdk/package/package.json +++ b/sdk/package/package.json @@ -1,6 +1,6 @@ { "name": "@start9labs/start-sdk", - "version": "0.4.0-beta.5", + "version": "0.4.0-beta.6", "description": "Software development kit to facilitate packaging services for StartOS", "main": "./package/lib/index.js", "types": "./package/lib/index.d.ts",