Skip to main content

townos_api/
status.rs

1//! Box-wide status: the overview counters and the core services.
2
3use crate::{Client, Ping, Result, SystemService};
4
5impl Client {
6    /// The dashboard counters.
7    ///
8    /// Unauthenticated — the control plane answers this without a token so a
9    /// client can tell a reachable box from an unreachable one before asking for
10    /// a password. `needs_setup` says the box has no enabled administrator yet.
11    ///
12    /// Calls `GET /status/ping`.
13    pub async fn ping(&self) -> Result<Ping> {
14        self.get_json("/status/ping").await
15    }
16
17    /// Calls `GET /system-services`.
18    pub async fn system_services(&self) -> Result<Vec<SystemService>> {
19        self.get_json("/system-services").await
20    }
21
22    /// Starts, stops or restarts a core service.
23    ///
24    /// Calls `POST /system-services/status` (admin).
25    pub async fn set_system_service(&self, key: &str, action: &str) -> Result<()> {
26        self.post_empty(
27            "/system-services/status",
28            &serde_json::json!({ "key": key, "action": action }),
29        )
30        .await
31    }
32}