Skip to content

Commit 279f2f0

Browse files
authored
Merge pull request fedora-iot#165 from say-paul/fix-deployment-type-detection
Fix deployment type detection
2 parents 33b27dc + b735dc0 commit 279f2f0

4 files changed

Lines changed: 22 additions & 21 deletions

File tree

.github/spellcheck-ignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ rw
99
RO
1010
RW
1111
grubenv
12-
msdos
12+
msdos
13+
waitFor

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "greenboot"
3-
version = "0.16.2"
3+
version = "0.16.3"
44
edition = "2024"
55
license = "BSD-3-Clause"
66

@@ -21,7 +21,7 @@ log = "0.4"
2121
clap = { version = "4.0", features = ["derive"] }
2222
config = "0.15.13"
2323
pretty_env_logger = "0.5.0"
24-
nix = "0.30.1"
24+
nix = "0.31.1"
2525
glob = "0.3.0"
2626
serde = "1.0"
2727
serde_json = "1.0"

greenboot-rs.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
%bcond bundled_rust_deps %{defined rhel}
88

99
Name: greenboot-rs
10-
Version: 0.16.2
10+
Version: 0.16.3
1111
Release: 0%{?dist}
1212
Summary: Generic Health Check Framework for systemd
1313
# Aggregated license of statically linked dependencies as per %%cargo_license_summary

src/lib/handler.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22

33
use anyhow::{Context, Result, anyhow, bail};
44
use serde_json::Value;
5+
use std::path::Path;
56
use std::process::Command;
67
use std::str;
78

89
use crate::grub::get_boot_counter;
910

10-
/// Detects if the system is managed by bootc or is a rpm-ostree system
11-
/// Inspect bootc status JSON and decide based on `status.booted.incompatible`.
11+
/// Detects if the system is managed by bootc or is a rpm-ostree system.
12+
/// First checks for `/run/ostree-booted`, then inspects `status.booted.image`
13+
/// from `bootc status --booted --json` to distinguish between the two.
1214
pub fn detect_os_deployment() -> Option<&'static str> {
15+
if !Path::new("/run/ostree-booted").exists() {
16+
log::info!("'/run/ostree-booted' not found, not an ostree-based system");
17+
return None;
18+
}
19+
1320
let output = match Command::new("bootc")
1421
.args(["status", "--booted", "--json"])
1522
.output()
@@ -31,24 +38,17 @@ pub fn detect_os_deployment() -> Option<&'static str> {
3138
}
3239
};
3340

34-
match json
41+
if let Some(image_type) = json
3542
.get("status")
3643
.and_then(|s| s.get("booted"))
37-
.and_then(|b| b.get("incompatible"))
38-
.and_then(|i| i.as_bool())
44+
.and_then(|b| b.get("image"))
45+
.filter(|v| !v.is_null())
3946
{
40-
Some(true) => {
41-
log::info!("System detected as rpm-ostree (incompatible=true)");
42-
Some("rpm-ostree")
43-
}
44-
Some(false) => {
45-
log::info!("System detected as bootc (incompatible=false)");
46-
Some("bootc")
47-
}
48-
None => {
49-
log::error!("bootc status JSON missing boolean field status.booted.incompatible");
50-
None
51-
}
47+
log::info!("System detected as bootc (status.booted.image: {image_type})");
48+
Some("bootc")
49+
} else {
50+
log::info!("System detected as rpm-ostree (status.booted.image is null or absent)");
51+
Some("rpm-ostree")
5252
}
5353
}
5454

0 commit comments

Comments
 (0)