From 2ef1d8fdbb5363e9d8bb422b74531ffa85a0d114 Mon Sep 17 00:00:00 2001 From: Danny Canter Date: Fri, 19 Sep 2025 08:56:23 -0700 Subject: [PATCH] CLI: Skip stopping containers in system stop if APIServer is down (#650) Today if you do system stop twice (or if you forgot the server isn't running) you get bombarded with annoying (and confusing) XPC interrupted messages. We should skip the container stop and list dance if we can't talk to the APIServer with a simple ping. --- .../ContainerCommands/System/SystemStop.swift | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/Sources/ContainerCommands/System/SystemStop.swift b/Sources/ContainerCommands/System/SystemStop.swift index b3179b3b..bd60893d 100644 --- a/Sources/ContainerCommands/System/SystemStop.swift +++ b/Sources/ContainerCommands/System/SystemStop.swift @@ -47,36 +47,47 @@ extension Application { let launchdDomainString = try ServiceManager.getDomainString() let fullLabel = "\(launchdDomainString)/\(prefix)apiserver" - log.info("stopping containers", metadata: ["stopTimeoutSeconds": "\(Self.stopTimeoutSeconds)"]) + var running = true do { - let containers = try await ClientContainer.list() - let signal = try Signals.parseSignal("SIGTERM") - let opts = ContainerStopOptions(timeoutInSeconds: Self.stopTimeoutSeconds, signal: signal) - let failed = try await ContainerStop.stopContainers(containers: containers, stopOptions: opts) - if !failed.isEmpty { - log.warning("some containers could not be stopped gracefully", metadata: ["ids": "\(failed)"]) - } - + log.info("checking if APIServer is alive") + _ = try await ClientHealthCheck.ping(timeout: .seconds(5)) } catch { - log.warning("failed to stop all containers", metadata: ["error": "\(error)"]) + log.info("APIServer health check failed, skipping bootout") + running = false } - log.info("waiting for containers to exit") - do { - for _ in 0..