@@ -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,7 +740,40 @@ 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
741
- /// Prepare and execute a soft reboot for the given deployment
743
+ /// If there is staged deployment, check if soft reboot is possible and prepare the system for it
744
+ fn should_soft_reboot (
745
+ sysroot : & crate :: store:: Storage ,
746
+ booted_deployment : Option < & ostree:: Deployment > ,
747
+ ) -> Result < bool > {
748
+ // Get updated status to check for soft-reboot capability
749
+ let ( _deployments, updated_host) = crate :: status:: get_status ( sysroot, booted_deployment) ?;
750
+
751
+ // Check if there's a staged deployment that can perform soft reboot
752
+ if can_perform_soft_reboot ( updated_host. status . staged . as_ref ( ) ) {
753
+ soft_reboot_staged ( sysroot) ?;
754
+ return Ok ( true ) ;
755
+ }
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
+ }
773
+ Ok ( false )
774
+ }
775
+
776
+ /// Prepare a soft reboot for the given deployment
742
777
#[ context( "Preparing soft reboot" ) ]
743
778
fn prepare_soft_reboot (
744
779
sysroot : & crate :: store:: Storage ,
@@ -887,9 +922,6 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
887
922
println ! ( "Staged update present, not changed." ) ;
888
923
889
924
if opts. apply {
890
- if can_perform_soft_reboot ( host. status . staged . as_ref ( ) ) {
891
- soft_reboot_staged ( sysroot) ?;
892
- }
893
925
crate :: reboot:: reboot ( ) ?;
894
926
}
895
927
} else if booted_unchanged {
@@ -986,12 +1018,6 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
986
1018
sysroot. update_mtime ( ) ?;
987
1019
988
1020
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
1021
crate :: reboot:: reboot ( ) ?;
996
1022
}
997
1023
@@ -1005,20 +1031,6 @@ async fn rollback(opts: RollbackOpts) -> Result<()> {
1005
1031
crate :: deploy:: rollback ( sysroot) . await ?;
1006
1032
1007
1033
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
1034
crate :: reboot:: reboot ( ) ?;
1023
1035
}
1024
1036
@@ -1302,6 +1314,17 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
1302
1314
}
1303
1315
} ,
1304
1316
InternalsOpts :: Reboot => crate :: reboot:: reboot ( ) ,
1317
+ InternalsOpts :: PrepareSoftReboot => {
1318
+ let sysroot = & get_storage ( ) . await ?;
1319
+ let booted_deployment = sysroot. booted_deployment ( ) ;
1320
+ let should_perform = should_soft_reboot ( sysroot, booted_deployment. as_ref ( ) ) ?;
1321
+ if should_perform {
1322
+ println ! ( "Soft reboot preparation completed" ) ;
1323
+ } else {
1324
+ println ! ( "Soft reboot not needed" ) ;
1325
+ }
1326
+ Ok ( ( ) )
1327
+ }
1305
1328
InternalsOpts :: Fsck => {
1306
1329
let sysroot = & get_storage ( ) . await ?;
1307
1330
crate :: fsck:: fsck ( & sysroot, std:: io:: stdout ( ) . lock ( ) ) . await ?;
0 commit comments