Skip to content

Commit

Permalink
client: Don't invoke systemctl start if unit is already active
Browse files Browse the repository at this point in the history
Adding onto the pile of hacks here unfortunately.  Basically
RHEL8 systemd seems to count explicit `systemctl start` invocations
against the restart limit.  We hit this in tests in openshift/machine-config-operator
which are invoking `rpm-ostree status` and `rpm-ostree kargs` frequently.
  • Loading branch information
cgwalters committed Mar 16, 2022
1 parent 3c72f5a commit b21cbd9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions rust/src/client.rs
Expand Up @@ -156,12 +156,30 @@ pub(crate) fn client_handle_fd_argument(arg: &str, arch: &str) -> CxxResult<Vec<
/// Basically we load too much data before claiming the bus name,
/// and dbus doesn't give us a useful error. Instead, let's talk
/// to systemd directly and use its client tools to scrape errors.
///
/// What we really should do probably is use native socket activation.
pub(crate) fn client_start_daemon() -> CxxResult<()> {
let service = "rpm-ostreed.service";
// Assume non-root can't use systemd right now.
if rustix::process::getuid().as_raw() != 0 {
return Ok(());
}
// Unfortunately, RHEL8 systemd will count "systemctl start"
// invocations against the restart limit, so query the status
// first.
let activeres = Command::new("systemctl")
.args(&["is-active", "rpm-ostreed"])
.output()?;
if !activeres.status.success() {
return Err(format!(
"Failed to run systemctl is-active rpm-ostreed: {}",
activeres.status
)
.into());
}
if String::from_utf8_lossy(&activeres.stdout).starts_with("active") {
return Ok(());
}
let res = Command::new("systemctl")
.args(&["--no-ask-password", "start", service])
.status()?;
Expand Down

0 comments on commit b21cbd9

Please sign in to comment.