MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / execute

Method execute

src/commands/server/stop.rs:11–45  ·  view source on GitHub ↗
(&self, ctx: &AppContext)

Source from the content-addressed store, hash-verified

9#[async_trait]
10impl Command for ServerStopCommand {
11 async fn execute(&self, ctx: &AppContext) -> Result<(), Box<dyn Error>> {
12 println!("Stopping tsk server...");
13
14 let lifecycle = ServerLifecycle::new(ctx.tsk_env());
15
16 let pid = match lifecycle.read_pid() {
17 Some(pid) if lifecycle.is_server_running() => pid,
18 _ => {
19 println!("Server is not running");
20 return Ok(());
21 }
22 };
23
24 if !lifecycle.send_sigterm(pid) {
25 eprintln!("Failed to send SIGTERM to server process (PID {pid})");
26 return Err(Box::new(std::io::Error::other(format!(
27 "Failed to send SIGTERM to process {pid}"
28 ))));
29 }
30
31 let poll_interval = tokio::time::Duration::from_millis(200);
32 let timeout = tokio::time::Duration::from_secs(10);
33 let start = tokio::time::Instant::now();
34
35 while start.elapsed() < timeout {
36 tokio::time::sleep(poll_interval).await;
37 if !lifecycle.is_server_running() {
38 println!("Server stopped successfully");
39 return Ok(());
40 }
41 }
42
43 eprintln!("Warning: Server may still be running after timeout");
44 Ok(())
45 }
46}

Callers

nothing calls this directly

Calls 4

tsk_envMethod · 0.80
read_pidMethod · 0.80
is_server_runningMethod · 0.80
send_sigtermMethod · 0.80

Tested by

no test coverage detected