Skip to content

Commit 20b6325

Browse files
authored
Add new system status command (#118)
Container services can be started and stopped using the `system start` and `system stop` commands. But there is no straightforward way for users to check if the services were already started. This PR adds a new `system status` command that shows wether the container services are running or not. The command only checks the status of the apiserver for now, but it could be expanded in the future to show more details. Fixes #117.
1 parent 3a76848 commit 20b6325

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

Sources/CLI/System/SystemCommand.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extension Application {
2727
SystemRestart.self,
2828
SystemStart.self,
2929
SystemStop.self,
30+
SystemStatus.self,
3031
SystemKernel.self,
3132
],
3233
aliases: ["s"]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===----------------------------------------------------------------------===//
2+
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//===----------------------------------------------------------------------===//
16+
17+
import ArgumentParser
18+
import ContainerClient
19+
import ContainerPlugin
20+
import ContainerizationError
21+
import Foundation
22+
import Logging
23+
24+
extension Application {
25+
struct SystemStatus: AsyncParsableCommand {
26+
static let configuration = CommandConfiguration(
27+
commandName: "status",
28+
abstract: "Show the status of `container` services"
29+
)
30+
31+
@Option(name: .shortAndLong, help: "Launchd prefix for `container` services")
32+
var prefix: String = "com.apple.container."
33+
34+
func run() async throws {
35+
let isRegistered = try ServiceManager.isRegistered(fullServiceLabel: "\(prefix)apiserver")
36+
if !isRegistered {
37+
print("apiserver is not running and not registered with launchd")
38+
Application.exit(withError: ExitCode(1))
39+
}
40+
41+
// Now ping our friendly daemon. Fail after 10 seconds with no response.
42+
do {
43+
print("Verifying apiserver is running...")
44+
try await ClientHealthCheck.ping(timeout: .seconds(10))
45+
print("apiserver is running")
46+
} catch {
47+
print("apiserver is not running")
48+
Application.exit(withError: ExitCode(1))
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)