Skip to content

Commit 7aa6990

Browse files
frido22webhive
authored andcommitted
feat(status): show service running state in zeroclaw status (zeroclaw-labs#3751)
1 parent 1156af6 commit 7aa6990

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,11 @@ async fn main() -> Result<()> {
11181118
);
11191119
println!("🛡️ Autonomy: {:?}", config.autonomy.level);
11201120
println!("⚙️ Runtime: {}", config.runtime.kind);
1121+
if service::is_running() {
1122+
println!("🟢 Service: running");
1123+
} else {
1124+
println!("🔴 Service: stopped");
1125+
}
11211126
let effective_memory_backend = memory::effective_memory_backend_name(
11221127
&config.memory.backend,
11231128
Some(&config.storage.provider.config),

src/service/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,42 @@ fn windows_task_name() -> &'static str {
8989
WINDOWS_TASK_NAME
9090
}
9191

92+
/// Returns whether the ZeroClaw daemon service is currently running.
93+
pub fn is_running() -> bool {
94+
if cfg!(target_os = "macos") {
95+
run_capture(Command::new("launchctl").arg("list"))
96+
.map(|out| out.lines().any(|l| l.contains(SERVICE_LABEL)))
97+
.unwrap_or(false)
98+
} else if cfg!(target_os = "linux") {
99+
is_running_linux()
100+
} else if cfg!(target_os = "windows") {
101+
run_capture(Command::new("schtasks").args([
102+
"/Query",
103+
"/TN",
104+
WINDOWS_TASK_NAME,
105+
"/FO",
106+
"LIST",
107+
]))
108+
.map(|out| out.contains("Running"))
109+
.unwrap_or(false)
110+
} else {
111+
false
112+
}
113+
}
114+
115+
fn is_running_linux() -> bool {
116+
// Try systemd first, then OpenRC — mirrors detect_init_system() order
117+
if run_capture(Command::new("systemctl").args(["--user", "is-active", "zeroclaw.service"]))
118+
.map(|out| out.trim() == "active")
119+
.unwrap_or(false)
120+
{
121+
return true;
122+
}
123+
run_capture(Command::new("rc-service").args(["zeroclaw", "status"]))
124+
.map(|out| out.contains("started"))
125+
.unwrap_or(false)
126+
}
127+
92128
pub fn handle_command(
93129
command: &crate::ServiceCommands,
94130
config: &Config,

0 commit comments

Comments
 (0)