Skip to main content

objectiveai_cli/command/daemon/
kill.rs

1//! `daemon kill` — stop the per-state plugin daemon. Its leashed
2//! `daemon: true` plugins die with it.
3
4use objectiveai_sdk::cli::command::daemon::kill::{Request, Response};
5
6use crate::context::Context;
7use crate::error::Error;
8
9pub async fn execute(ctx: &Context, _request: Request) -> Result<Response, Error> {
10    let lock_dir = ctx.filesystem.state_dir().join("locks");
11
12    // Live owner PID(s) of the daemon lock → kill them. The daemon's
13    // `daemon: true` plugins are leashed to it, so they die with it.
14    let pids = objectiveai_sdk::lockfile::owners(&lock_dir, super::DAEMON_LOCK_KEY)
15        .await
16        .map_err(|e| Error::Lockfile {
17            key: super::DAEMON_LOCK_KEY.to_string(),
18            source: e,
19        })?;
20    let mut killed = 0usize;
21    for pid in pids {
22        killed += crate::spawn::kill_pid(pid);
23    }
24
25    Ok(Response { killed })
26}
27
28pub mod request_schema {
29    use objectiveai_sdk::cli::command::daemon::kill as sdk;
30    use objectiveai_sdk::cli::command::daemon::kill::request_schema::{Request, Response};
31
32    use crate::context::Context;
33    use crate::error::Error;
34
35    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
36        Ok(objectiveai_sdk::cli::command::ResponseSchema(schemars::schema_for!(sdk::Request)))
37    }
38}
39
40pub mod response_schema {
41    use objectiveai_sdk::cli::command::daemon::kill as sdk;
42    use objectiveai_sdk::cli::command::daemon::kill::response_schema::{Request, Response};
43
44    use crate::context::Context;
45    use crate::error::Error;
46
47    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
48        Ok(objectiveai_sdk::cli::command::ResponseSchema(schemars::schema_for!(sdk::Response)))
49    }
50}