@@ -485,6 +485,8 @@ pub(crate) enum InternalsOpts {
485
485
/// Initiate a reboot the same way we would after --apply; intended
486
486
/// primarily for testing.
487
487
Reboot ,
488
+ /// Check if soft reboot should be performed and prepare if needed
489
+ PrepareSoftReboot ,
488
490
#[ cfg( feature = "rhsm" ) ]
489
491
/// Publish subscription-manager facts to /etc/rhsm/facts/bootc.facts
490
492
PublishRhsmFacts ,
@@ -738,6 +740,25 @@ fn can_perform_soft_reboot(deployment: Option<&crate::spec::BootEntry>) -> bool
738
740
deployment. map ( |d| d. soft_reboot_capable ) . unwrap_or ( false )
739
741
}
740
742
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
+
741
762
/// Prepare and execute a soft reboot for the given deployment
742
763
#[ context( "Preparing soft reboot" ) ]
743
764
fn prepare_soft_reboot (
@@ -887,9 +908,6 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
887
908
println ! ( "Staged update present, not changed." ) ;
888
909
889
910
if opts. apply {
890
- if can_perform_soft_reboot ( host. status . staged . as_ref ( ) ) {
891
- soft_reboot_staged ( sysroot) ?;
892
- }
893
911
crate :: reboot:: reboot ( ) ?;
894
912
}
895
913
} else if booted_unchanged {
@@ -986,12 +1004,6 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
986
1004
sysroot. update_mtime ( ) ?;
987
1005
988
1006
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
- }
995
1007
crate :: reboot:: reboot ( ) ?;
996
1008
}
997
1009
@@ -1005,20 +1017,6 @@ async fn rollback(opts: RollbackOpts) -> Result<()> {
1005
1017
crate :: deploy:: rollback ( sysroot) . await ?;
1006
1018
1007
1019
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
-
1022
1020
crate :: reboot:: reboot ( ) ?;
1023
1021
}
1024
1022
@@ -1302,6 +1300,17 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
1302
1300
}
1303
1301
} ,
1304
1302
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
+ }
1305
1314
InternalsOpts :: Fsck => {
1306
1315
let sysroot = & get_storage ( ) . await ?;
1307
1316
crate :: fsck:: fsck ( & sysroot, std:: io:: stdout ( ) . lock ( ) ) . await ?;
0 commit comments