Skip to content

Commit a01ce3d

Browse files
committed
Add function to write reboot-required file with context
This change adds a function that writes the /run/reboot-required file. This function is called from any deployment operation with the relevant context. Calling from rollback will ensure the rollback context along with the image digest is written to the file, while calling from upgrade or switch will write the deploy context for users to reference. This expands on the functionality requested in: #1574 Related to: #1583 Signed-off-by: Brendan Shephard <bshephar@bne-home.net>
1 parent 39b0a32 commit a01ce3d

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

crates/lib/src/deploy.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,19 @@ pub(crate) async fn stage(
792792
})
793793
.await;
794794

795+
let bootc_action: String = String::from("deploy");
796+
795797
// Unconditionally create or update /run/reboot-required to signal a reboot is needed.
796798
// This is monitored by kured (Kubernetes Reboot Daemon).
797-
let reboot_message = format!("bootc: Reboot required for image: {}", &spec.image.image);
799+
write_reboot_required(&image.manifest_digest.as_ref(), bootc_action.as_str())?;
800+
801+
Ok(())
802+
}
803+
804+
/// Update the /run/reboot-required file with the action we're performing,
805+
/// and the image that will be active after the reboot.
806+
fn write_reboot_required(image: &str, action: &str) -> Result<()> {
807+
let reboot_message = format!("bootc {}: Reboot required for image: {}", action, image);
798808
let run_dir = Dir::open_ambient_dir("/run", cap_std::ambient_authority())?;
799809
run_dir
800810
.atomic_write("reboot-required", reboot_message.as_bytes())
@@ -870,6 +880,12 @@ pub(crate) async fn rollback(sysroot: &Storage) -> Result<()> {
870880
println!("Next boot: rollback deployment");
871881
}
872882

883+
let bootc_action: String = String::from("rollback");
884+
write_reboot_required(
885+
rollback_image.manifest_digest.as_ref(),
886+
bootc_action.as_str(),
887+
)?;
888+
873889
sysroot.update_mtime()?;
874890

875891
Ok(())

0 commit comments

Comments
 (0)