File tree Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -33,9 +33,17 @@ pub(crate) struct UpgradeOpts {
33
33
#[ clap( long) ]
34
34
pub ( crate ) touch_if_changed : Option < Utf8PathBuf > ,
35
35
36
- /// Check if an update is available without applying it
37
- #[ clap( long) ]
36
+ /// Check if an update is available without applying it.
37
+ #[ clap( long, conflicts_with = "apply" ) ]
38
38
pub ( crate ) check : bool ,
39
+
40
+ /// Restart or reboot into the new target image.
41
+ ///
42
+ /// Currently, this option always reboots. In the future this command
43
+ /// will detect the case where no kernel changes are queued, and perform
44
+ /// a userspace-only restart.
45
+ #[ clap( long, conflicts_with = "check" ) ]
46
+ pub ( crate ) apply : bool ,
39
47
}
40
48
41
49
/// Perform an switch operation
@@ -364,6 +372,11 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
364
372
if let Some ( path) = opts. touch_if_changed {
365
373
std:: fs:: write ( & path, "" ) . with_context ( || format ! ( "Writing {path}" ) ) ?;
366
374
}
375
+ if opts. apply {
376
+ crate :: reboot:: reboot ( ) ?;
377
+ }
378
+ } else {
379
+ tracing:: debug!( "No changes" ) ;
367
380
}
368
381
369
382
Ok ( ( ) )
Original file line number Diff line number Diff line change 16
16
pub mod cli;
17
17
pub ( crate ) mod deploy;
18
18
mod lsm;
19
+ mod reboot;
19
20
mod reexec;
20
21
mod status;
21
22
mod utils;
Original file line number Diff line number Diff line change
1
+ //! Handling of system restarts/reboot
2
+
3
+ use std:: io:: Write ;
4
+ use std:: process:: Command ;
5
+
6
+ use fn_error_context:: context;
7
+
8
+ /// Initiate a system reboot.
9
+ /// This function will only return in case of error.
10
+ #[ context( "Initiating reboot" ) ]
11
+ pub ( crate ) fn reboot ( ) -> anyhow:: Result < ( ) > {
12
+ // Flush output streams
13
+ let _ = std:: io:: stdout ( ) . flush ( ) ;
14
+ let _ = std:: io:: stderr ( ) . flush ( ) ;
15
+ let st = Command :: new ( "reboot" ) . status ( ) ?;
16
+ if !st. success ( ) {
17
+ anyhow:: bail!( "Failed to reboot: {st:?}" ) ;
18
+ }
19
+ tracing:: debug!( "Initiated reboot, sleeping forever..." ) ;
20
+ loop {
21
+ std:: thread:: park ( ) ;
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments