Skip to main content

systemprompt_cli/commands/infrastructure/services/restart/
mod.rs

1//! Service restart handlers shared by the single-target and batch restart
2//! paths.
3//!
4//! Re-exports the per-target entry points ([`execute_api`], [`execute_agent`],
5//! [`execute_mcp`]) and the batch entry points ([`execute_all_agents`],
6//! [`execute_all_mcp`], [`execute_failed`]). Batch paths compute a
7//! [`systemprompt_scheduler::RestartPlan`] from the observed service state
8//! and drive the orchestrators composed in the parent module's `lifecycle`.
9//!
10//! Copyright (c) systemprompt.io — Business Source License 1.1.
11//! See <https://systemprompt.io> for licensing details.
12
13mod batch;
14mod single;
15
16use systemprompt_logging::CliService;
17
18use super::get_api_port;
19
20pub use batch::{execute_all_agents, execute_all_mcp, execute_failed};
21pub use single::{execute_agent, execute_api, execute_mcp};
22
23pub fn format_batch_message(
24    service_label: &str,
25    restarted: usize,
26    failed: usize,
27    quiet: bool,
28) -> String {
29    match (restarted, failed) {
30        (0, 0) => {
31            let msg = format!("No enabled {} found", service_label);
32            if !quiet {
33                CliService::info(&msg);
34            }
35            msg
36        },
37        (r, 0) => {
38            let msg = format!("Restarted {} {}", r, service_label);
39            if !quiet {
40                CliService::success(&msg);
41            }
42            msg
43        },
44        (0, f) => {
45            let msg = format!("Failed to restart {} {}", f, service_label);
46            if !quiet {
47                CliService::warning(&msg);
48            }
49            msg
50        },
51        (r, f) => {
52            if !quiet {
53                CliService::success(&format!("Restarted {} {}", r, service_label));
54                CliService::warning(&format!("Failed to restart {} {}", f, service_label));
55            }
56            format!("Restarted {} {}, {} failed", r, service_label, f)
57        },
58    }
59}