Skip to content

Commit 8137806

Browse files
committed
Check if we are trying to Rollback
1 parent fa6bde3 commit 8137806

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

crates/lib/src/cli.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,7 @@ fn can_perform_soft_reboot(deployment: Option<&crate::spec::BootEntry>) -> bool
740740
deployment.map(|d| d.soft_reboot_capable).unwrap_or(false)
741741
}
742742

743-
/// If there is staged deployment, check if soft reboot is possible and perform it if possible and return true
744-
/// else return false
743+
/// If there is staged deployment, check if soft reboot is possible and prepare the system for it
745744
fn should_soft_reboot(
746745
sysroot: &crate::store::Storage,
747746
booted_deployment: Option<&ostree::Deployment>,
@@ -754,12 +753,27 @@ fn should_soft_reboot(
754753
soft_reboot_staged(sysroot)?;
755754
return Ok(true);
756755
}
757-
// TODO check if this reboot is doing a rollback...
758-
// TODO then perform a soft reboot for the rollback deployment
756+
757+
//Check if we are trying to rollback
758+
//Then prepare for soft reboot for the rollback deployment
759+
let host = crate::status::get_status_require_booted(sysroot)?.2;
760+
if host.spec.boot_order == crate::spec::BootOrder::Rollback {
761+
if can_perform_soft_reboot(host.status.rollback.as_ref()) {
762+
println!("Rollback deployment is soft-reboot capable, preparing for soft-reboot...");
763+
764+
let deployments_list = sysroot.deployments();
765+
let target_deployment = deployments_list
766+
.first()
767+
.ok_or_else(|| anyhow::anyhow!("No deployments found after rollback"))?;
768+
769+
prepare_soft_reboot(sysroot, target_deployment)?;
770+
return Ok(true);
771+
}
772+
}
759773
Ok(false)
760774
}
761775

762-
/// Prepare and execute a soft reboot for the given deployment
776+
/// Prepare a soft reboot for the given deployment
763777
#[context("Preparing soft reboot")]
764778
fn prepare_soft_reboot(
765779
sysroot: &crate::store::Storage,

systemd/bootc-soft-reboot.service

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Description=bootc soft reboot preparation
33
Documentation=man:bootc(8)
44
ConditionPathExists=/run/ostree-booted
55
DefaultDependencies=no
6-
Before=ostree-finalize-staged.service final.target
7-
Conflicts=final.target
6+
Before=reboot.target soft-reboot.target ostree-finalize-staged.service
7+
Conflicts=reboot.target soft-reboot.target
88

99
[Service]
1010
Type=oneshot
@@ -14,4 +14,4 @@ ExecStop=/usr/bin/bootc internals prepare-soft-reboot
1414
TimeoutStopSec=5m
1515

1616
[Install]
17-
WantedBy=multi-user.target
17+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)