fix list_containers reporting stale running state
handle_list_descendants derived a container's running state from membership in nixos-container list output, but that command returns every registered container - stopped and ghost-registered (machined still holds the name after the process died) ones included - not just running ones. use lifecycle::is_running (systemctl is-active on the container's systemd unit) per container instead, same source container_view::build_all already uses for the dashboard. fixes hyperhive/hyperhive#2846
This commit is contained in:
parent
d09ec31431
commit
a72009099a
1 changed files with 11 additions and 22 deletions
|
|
@ -160,21 +160,6 @@ pub(super) fn handle_update(coord: &Arc<Coordinator>, agent: &str, name: &str) -
|
||||||
/// its running/stopped state, parents before children.
|
/// its running/stopped state, parents before children.
|
||||||
pub(super) async fn handle_list_descendants(agent: &str) -> Response {
|
pub(super) async fn handle_list_descendants(agent: &str) -> Response {
|
||||||
tracing::debug!(%agent, "agent: list descendants");
|
tracing::debug!(%agent, "agent: list descendants");
|
||||||
// All containers known to nixos-container (running only).
|
|
||||||
let running_set: std::collections::HashSet<String> = match crate::lifecycle::list().await {
|
|
||||||
Ok(names) => names
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|c| {
|
|
||||||
c.strip_prefix(crate::lifecycle::AGENT_PREFIX)
|
|
||||||
.map(str::to_owned)
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
Err(e) => {
|
|
||||||
return Response::Err {
|
|
||||||
message: format!("list containers failed: {e:#}"),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Walk the full topology and collect every descendant.
|
// Walk the full topology and collect every descendant.
|
||||||
let topo = crate::topology::read();
|
let topo = crate::topology::read();
|
||||||
let mut names: Vec<String> = topo
|
let mut names: Vec<String> = topo
|
||||||
|
|
@ -184,12 +169,16 @@ pub(super) async fn handle_list_descendants(agent: &str) -> Response {
|
||||||
.collect();
|
.collect();
|
||||||
// Parents before children, then alpha within each tier.
|
// Parents before children, then alpha within each tier.
|
||||||
crate::auto_update::topology_sort(&mut names, &topo);
|
crate::auto_update::topology_sort(&mut names, &topo);
|
||||||
let containers = names
|
// Query each container's actual systemd unit state (same source
|
||||||
.into_iter()
|
// `container_view::build_all` uses for the dashboard). `nixos-container
|
||||||
.map(|name| {
|
// list` — what this used to key off of via a "known containers" set —
|
||||||
let running = running_set.contains(&name);
|
// reports every *registered* container, stopped and ghost-registered
|
||||||
hive_sh4re::ContainerInfo { name, running }
|
// (machined still holds the name after a crashed/killed process) ones
|
||||||
})
|
// included, so membership there is not the same thing as "running".
|
||||||
.collect();
|
let mut containers = Vec::with_capacity(names.len());
|
||||||
|
for name in names {
|
||||||
|
let running = crate::lifecycle::is_running(&name).await;
|
||||||
|
containers.push(hive_sh4re::ContainerInfo { name, running });
|
||||||
|
}
|
||||||
Response::Containers { containers }
|
Response::Containers { containers }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue