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