Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions crates/lib/src/reboot.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
//! Handling of system restarts/reboot
use std::io::Write;
use std::{io::Write, process::Command};

use bootc_utils::CommandRunExt;
use fn_error_context::context;

use crate::task::Task;

/// Initiate a system reboot.
/// This function will only return in case of error.
#[context("Initiating reboot")]
pub(crate) fn reboot() -> anyhow::Result<()> {
// Flush output streams
let _ = std::io::stdout().flush();
let _ = std::io::stderr().flush();
Task::new("Rebooting system", "systemd-run")
Command::new("systemd-run")
.args([
"--quiet",
"--",
"systemctl",
"reboot",
"--message=Initiated by bootc",
])
.run()?;
tracing::debug!("Initiated reboot, sleeping forever...");
.run_capture_stderr()?;
// We expect to be terminated via SIGTERM here. We sleep
// instead of exiting an exit would necessarily appear
// racy to calling processes in that sometimes we'd
// win the race to exit, other times might get killed
// via SIGTERM.
tracing::debug!("Initiated reboot, sleeping");
loop {
std::thread::park();
}
Expand Down