Skip to content

Commit 81ed850

Browse files
committed
start moving to systemd service model
1 parent 75b8806 commit 81ed850

File tree

2 files changed

+49
-23
lines changed

2 files changed

+49
-23
lines changed

crates/lib/src/cli.rs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ pub(crate) enum InternalsOpts {
485485
/// Initiate a reboot the same way we would after --apply; intended
486486
/// primarily for testing.
487487
Reboot,
488+
/// Check if soft reboot should be performed and prepare if needed
489+
PrepareSoftReboot,
488490
#[cfg(feature = "rhsm")]
489491
/// Publish subscription-manager facts to /etc/rhsm/facts/bootc.facts
490492
PublishRhsmFacts,
@@ -738,6 +740,25 @@ fn can_perform_soft_reboot(deployment: Option<&crate::spec::BootEntry>) -> bool
738740
deployment.map(|d| d.soft_reboot_capable).unwrap_or(false)
739741
}
740742

743+
/// If there is staged deployment, check if soft reboot is possible and perform it if possible and return true
744+
/// else return false
745+
fn should_soft_reboot(
746+
sysroot: &crate::store::Storage,
747+
booted_deployment: Option<&ostree::Deployment>,
748+
) -> Result<bool> {
749+
// Get updated status to check for soft-reboot capability
750+
let (_deployments, updated_host) = crate::status::get_status(sysroot, booted_deployment)?;
751+
752+
// Check if there's a staged deployment that can perform soft reboot
753+
if can_perform_soft_reboot(updated_host.status.staged.as_ref()) {
754+
soft_reboot_staged(sysroot)?;
755+
return Ok(true);
756+
}
757+
// TODO check if this reboot is doing a rollback...
758+
// TODO then perform a soft reboot for the rollback deployment
759+
Ok(false)
760+
}
761+
741762
/// Prepare and execute a soft reboot for the given deployment
742763
#[context("Preparing soft reboot")]
743764
fn prepare_soft_reboot(
@@ -887,9 +908,6 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
887908
println!("Staged update present, not changed.");
888909

889910
if opts.apply {
890-
if can_perform_soft_reboot(host.status.staged.as_ref()) {
891-
soft_reboot_staged(sysroot)?;
892-
}
893911
crate::reboot::reboot()?;
894912
}
895913
} else if booted_unchanged {
@@ -986,12 +1004,6 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
9861004
sysroot.update_mtime()?;
9871005

9881006
if opts.apply {
989-
// Get updated status to check for soft-reboot capability
990-
let updated_host = crate::status::get_status(sysroot, Some(&booted_deployment))?.1;
991-
992-
if can_perform_soft_reboot(updated_host.status.staged.as_ref()) {
993-
soft_reboot_staged(sysroot)?;
994-
}
9951007
crate::reboot::reboot()?;
9961008
}
9971009

@@ -1005,20 +1017,6 @@ async fn rollback(opts: RollbackOpts) -> Result<()> {
10051017
crate::deploy::rollback(sysroot).await?;
10061018

10071019
if opts.apply {
1008-
// Get status before rollback to check soft-reboot capability
1009-
let host = crate::status::get_status_require_booted(sysroot)?.2;
1010-
1011-
if can_perform_soft_reboot(host.status.rollback.as_ref()) {
1012-
println!("Rollback deployment is soft-reboot capable, performing soft-reboot...");
1013-
1014-
let deployments_list = sysroot.deployments();
1015-
let target_deployment = deployments_list
1016-
.first()
1017-
.ok_or_else(|| anyhow::anyhow!("No deployments found after rollback"))?;
1018-
1019-
prepare_soft_reboot(sysroot, target_deployment)?;
1020-
}
1021-
10221020
crate::reboot::reboot()?;
10231021
}
10241022

@@ -1302,6 +1300,17 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
13021300
}
13031301
},
13041302
InternalsOpts::Reboot => crate::reboot::reboot(),
1303+
InternalsOpts::PrepareSoftReboot => {
1304+
let sysroot = &get_storage().await?;
1305+
let booted_deployment = sysroot.booted_deployment();
1306+
let should_perform = should_soft_reboot(sysroot, booted_deployment.as_ref())?;
1307+
if should_perform {
1308+
println!("Soft reboot preparation completed");
1309+
} else {
1310+
println!("Soft reboot not needed");
1311+
}
1312+
Ok(())
1313+
}
13051314
InternalsOpts::Fsck => {
13061315
let sysroot = &get_storage().await?;
13071316
crate::fsck::fsck(&sysroot, std::io::stdout().lock()).await?;

systemd/bootc-soft-reboot.service

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[Unit]
2+
Description=bootc soft reboot preparation
3+
Documentation=man:bootc(8)
4+
ConditionPathExists=/run/ostree-booted
5+
DefaultDependencies=no
6+
Before=ostree-finalize-staged.service final.target
7+
Conflicts=final.target
8+
9+
[Service]
10+
Type=oneshot
11+
RemainAfterExit=yes
12+
ExecStart=/bin/true
13+
ExecStop=/usr/bin/bootc internals prepare-soft-reboot
14+
TimeoutStopSec=5m
15+
16+
[Install]
17+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)