Skip to content

Commit

Permalink
bootupctl: Clear failure status from previous runs
Browse files Browse the repository at this point in the history
If for whatever reason a bootupd command fails, it will leave the
systemd service unit in a failed state and systemd will then refuse to
run a unit under the same name with `systemd-run` again until the
failure is cleared.

Thus systematically call `systemctl reset-failed` before calling
`systemd-run` to clear any potential failures from previous calls.

Do not check the return code of the systemctl command on purpose as it
may fail if the unit does not exists yet, i.e. if no bootupctl command
has been run yet.

Also ignore stdout/stderr to avoid showing unexpected errors messages to
users.

See: #707
See: #663
  • Loading branch information
travier committed Sep 2, 2024
1 parent 9bc21ba commit 6fcc010
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/cli/bootupctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::Parser;
use log::LevelFilter;

use std::os::unix::process::CommandExt;
use std::process::Command;
use std::process::{Command, Stdio};

static SYSTEMD_ARGS_BOOTUPD: &[&str] = &[
"--unit",
Expand Down Expand Up @@ -154,6 +154,14 @@ fn ensure_running_in_systemd() -> Result<()> {
require_root_permission()?;
let running_in_systemd = running_in_systemd();
if !running_in_systemd {
// Clear any failure status that may have happened previously
let _r = Command::new("systemctl")
.arg("reset-failed")
.arg("bootupd.service")
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()?
.wait()?;
let r = Command::new("systemd-run")
.args(SYSTEMD_ARGS_BOOTUPD)
.args(std::env::args())
Expand Down

0 comments on commit 6fcc010

Please sign in to comment.