Skip to main content

systemprompt_cli/commands/infrastructure/services/
mod.rs

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