diff --git a/crates/lib/src/bootc_composefs/mod.rs b/crates/lib/src/bootc_composefs/mod.rs index c19dbfb7..ee8a742e 100644 --- a/crates/lib/src/bootc_composefs/mod.rs +++ b/crates/lib/src/bootc_composefs/mod.rs @@ -2,6 +2,7 @@ pub(crate) mod boot; pub(crate) mod finalize; pub(crate) mod repo; pub(crate) mod rollback; +pub(crate) mod service; pub(crate) mod state; pub(crate) mod status; pub(crate) mod switch; diff --git a/crates/lib/src/bootc_composefs/repo.rs b/crates/lib/src/bootc_composefs/repo.rs index 3988125f..34ffb941 100644 --- a/crates/lib/src/bootc_composefs/repo.rs +++ b/crates/lib/src/bootc_composefs/repo.rs @@ -91,7 +91,7 @@ pub(crate) async fn pull_composefs_repo( .await .context("Pulling composefs repo")?; - tracing::info!("id: {}, verity: {}", hex::encode(id), verity.to_hex()); + tracing::info!("ID: {}, Verity: {}", hex::encode(id), verity.to_hex()); let repo = open_composefs_repo(&rootfs_dir)?; let mut fs: crate::store::ComposefsFilesystem = diff --git a/crates/lib/src/bootc_composefs/service.rs b/crates/lib/src/bootc_composefs/service.rs new file mode 100644 index 00000000..fdf4136a --- /dev/null +++ b/crates/lib/src/bootc_composefs/service.rs @@ -0,0 +1,22 @@ +use anyhow::{Context, Result}; +use fn_error_context::context; +use std::process::Command; + +use crate::composefs_consts::BOOTC_FINALIZE_STAGED_SERVICE; + +/// Starts the finaize staged service which will "unstage" the deployment +/// This is called before an upgrade or switch operation, as these create a staged +/// deployment +#[context("Starting finalize staged service")] +pub(crate) fn start_finalize_stated_svc() -> Result<()> { + let cmd_status = Command::new("systemctl") + .args(["start", "--quiet", BOOTC_FINALIZE_STAGED_SERVICE]) + .status() + .context("Starting finalize service")?; + + if !cmd_status.success() { + anyhow::bail!("systemctl exited with status {cmd_status}") + } + + Ok(()) +} diff --git a/crates/lib/src/bootc_composefs/switch.rs b/crates/lib/src/bootc_composefs/switch.rs index bebb9539..485fc59d 100644 --- a/crates/lib/src/bootc_composefs/switch.rs +++ b/crates/lib/src/bootc_composefs/switch.rs @@ -6,6 +6,7 @@ use crate::{ bootc_composefs::{ boot::{setup_composefs_bls_boot, setup_composefs_uki_boot, BootSetupType, BootType}, repo::pull_composefs_repo, + service::start_finalize_stated_svc, state::write_composefs_state, status::composefs_deployment_status, }, @@ -36,6 +37,8 @@ pub(crate) async fn switch_composefs(opts: SwitchOpts) -> Result<()> { anyhow::bail!("Target image is undefined") }; + start_finalize_stated_svc()?; + let (repo, entries, id, fs) = pull_composefs_repo(&target_imgref.transport, &target_imgref.image).await?; diff --git a/crates/lib/src/bootc_composefs/update.rs b/crates/lib/src/bootc_composefs/update.rs index 823a50be..018d8f3e 100644 --- a/crates/lib/src/bootc_composefs/update.rs +++ b/crates/lib/src/bootc_composefs/update.rs @@ -6,6 +6,7 @@ use crate::{ bootc_composefs::{ boot::{setup_composefs_bls_boot, setup_composefs_uki_boot, BootSetupType, BootType}, repo::pull_composefs_repo, + service::start_finalize_stated_svc, state::write_composefs_state, status::composefs_deployment_status, }, @@ -14,12 +15,12 @@ use crate::{ #[context("Upgrading composefs")] pub(crate) async fn upgrade_composefs(_opts: UpgradeOpts) -> Result<()> { - // TODO: IMPORTANT Have all the checks here that `bootc upgrade` has for an ostree booted system - let host = composefs_deployment_status() .await .context("Getting composefs deployment status")?; + start_finalize_stated_svc()?; + // TODO: IMPORTANT We need to check if any deployment is staged and get the image from that let imgref = host .spec diff --git a/crates/lib/src/composefs_consts.rs b/crates/lib/src/composefs_consts.rs index 453576ca..c9e6f751 100644 --- a/crates/lib/src/composefs_consts.rs +++ b/crates/lib/src/composefs_consts.rs @@ -36,3 +36,5 @@ pub(crate) const USER_CFG_STAGED: &str = "user.cfg.staged"; /// This is relative to the boot/efi directory pub(crate) const TYPE1_ENT_PATH: &str = "loader/entries"; pub(crate) const TYPE1_ENT_PATH_STAGED: &str = "loader/entries.staged"; + +pub(crate) const BOOTC_FINALIZE_STAGED_SERVICE: &str = "bootc-finalize-staged.service"; diff --git a/systemd/composefs-finalize-staged.service b/systemd/bootc-finalize-staged.service similarity index 100% rename from systemd/composefs-finalize-staged.service rename to systemd/bootc-finalize-staged.service