(&self, ctx: &AppContext)
| 9 | #[async_trait] |
| 10 | impl 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 | } |
nothing calls this directly
no test coverage detected