systemprompt_cli/commands/infrastructure/services/
mod.rs1mod cleanup;
9mod dispatch;
10pub mod restart;
11pub mod serve;
12mod start;
13mod status;
14mod stop;
15mod types;
16
17use clap::Subcommand;
18use systemprompt_config::ProfileBootstrap;
19
20pub use dispatch::{execute, load_service_configs};
21
22const DEFAULT_API_PORT: u16 = 8080;
23
24pub(super) fn get_api_port() -> u16 {
25 ProfileBootstrap::get().map_or(DEFAULT_API_PORT, |p| p.server.port)
26}
27
28#[derive(Debug, Clone, Subcommand)]
29pub enum StartTarget {
30 #[command(about = "Start a single agent by name")]
31 Agent { agent: String },
32 #[command(about = "Start a single MCP server by name")]
33 Mcp { server_name: String },
34}
35
36#[derive(Debug, Clone, Subcommand)]
37pub enum StopTarget {
38 #[command(about = "Stop a single agent by name")]
39 Agent {
40 agent: String,
41 #[arg(long, help = "Force stop (SIGKILL)")]
42 force: bool,
43 },
44 #[command(about = "Stop a single MCP server by name")]
45 Mcp {
46 server_name: String,
47 #[arg(long, help = "Force stop (SIGKILL)")]
48 force: bool,
49 },
50}
51
52#[derive(Debug, Subcommand)]
53pub enum ServicesCommands {
54 #[command(
55 about = "Start API, agents, and MCP servers",
56 after_help = "EXAMPLES:\n systemprompt infra services start\n systemprompt infra \
57 services start --api\n systemprompt infra services start --agents --mcp\n \
58 systemprompt infra services start agent <name>"
59 )]
60 Start {
61 #[command(subcommand)]
62 target: Option<StartTarget>,
63
64 #[arg(long, help = "Start all services")]
65 all: bool,
66
67 #[arg(long, help = "Start API server only")]
68 api: bool,
69
70 #[arg(long, help = "Start agents only")]
71 agents: bool,
72
73 #[arg(long, help = "Start MCP servers only")]
74 mcp: bool,
75
76 #[arg(long, help = "Run in foreground (default)")]
77 foreground: bool,
78
79 #[arg(long, help = "Skip database migrations")]
80 skip_migrate: bool,
81
82 #[arg(long, help = "Kill process using the port if occupied")]
83 kill_port_process: bool,
84 },
85
86 #[command(
87 about = "Stop running services gracefully",
88 after_help = "EXAMPLES:\n systemprompt infra services stop\n systemprompt infra \
89 services stop --api\n systemprompt infra services stop agent <name> \
90 [--force]"
91 )]
92 Stop {
93 #[command(subcommand)]
94 target: Option<StopTarget>,
95
96 #[arg(long, help = "Stop all services")]
97 all: bool,
98
99 #[arg(long, help = "Stop API server only")]
100 api: bool,
101
102 #[arg(long, help = "Stop agents only")]
103 agents: bool,
104
105 #[arg(long, help = "Stop MCP servers only")]
106 mcp: bool,
107
108 #[arg(long, help = "Force stop (SIGKILL)")]
109 force: bool,
110 },
111
112 #[command(about = "Restart services")]
113 Restart {
114 #[command(subcommand)]
115 target: Option<RestartTarget>,
116
117 #[arg(long, help = "Restart only failed services")]
118 failed: bool,
119
120 #[arg(long, help = "Restart all agents")]
121 agents: bool,
122
123 #[arg(long, help = "Restart all MCP servers")]
124 mcp: bool,
125 },
126
127 #[command(about = "Show detailed service status")]
128 Status {
129 #[arg(long, help = "Show detailed information")]
130 detailed: bool,
131
132 #[arg(long, help = "Output as JSON")]
133 json: bool,
134
135 #[arg(long, help = "Include health check results")]
136 health: bool,
137 },
138
139 #[command(about = "Clean up orphaned processes and stale entries")]
140 Cleanup {
141 #[arg(short = 'y', long, help = "Skip confirmation prompt")]
142 yes: bool,
143
144 #[arg(long, help = "Preview cleanup without executing")]
145 dry_run: bool,
146 },
147
148 #[command(about = "Start API server (automatically starts agents and MCP servers)")]
149 Serve {
150 #[arg(long, help = "Run in foreground mode")]
151 foreground: bool,
152
153 #[arg(long, help = "Kill process using the port if occupied")]
154 kill_port_process: bool,
155 },
156}
157
158#[derive(Debug, Clone, Subcommand)]
159pub enum RestartTarget {
160 #[command(about = "Restart the API server")]
161 Api,
162 #[command(about = "Restart a single agent by name")]
163 Agent { agent: String },
164 #[command(about = "Restart a single MCP server by name")]
165 Mcp {
166 server_name: String,
167 #[arg(long, help = "Rebuild the binary before restarting")]
168 build: bool,
169 },
170}