MCPcopy Create free account
hub / github.com/Autoparallel/learner / stop

Method stop

crates/learnerd/src/daemon/mod.rs:291–315  ·  view source on GitHub ↗

TODO (autoparallel): this is actually never really able to be used at the moment. Attempts to stop a running daemon process. Sends SIGTERM to the process identified by PID file and performs cleanup. # Errors Returns `LearnerdErrors` if: - PID file is missing or invalid - Process termination fails - Cleanup fails # Note Currently has limited functionality - see TODO in implementation.

(&self)

Source from the content-addressed store, hash-verified

289 ///
290 /// Currently has limited functionality - see TODO in implementation.
291 pub fn stop(&self) -> Result<()> {
292 if let Ok(pid) = fs::read_to_string(&self.pid_file) {
293 let pid: i32 = pid.trim().parse().map_err(|e: std::num::ParseIntError| {
294 LearnerdError::Daemon(format!("pid.trim().parse() gave error: {}", e))
295 })?;
296
297 #[cfg(unix)]
298 {
299 // Send SIGTERM to the process
300 if let Err(e) = signal::kill(Pid::from_raw(pid), Signal::SIGTERM) {
301 error!("Failed to send SIGTERM to process: {}", e);
302 return Err(LearnerdError::Daemon(format!("Failed to stop daemon: {}", e)));
303 }
304 }
305
306 if let Err(e) = fs::remove_file(&self.pid_file) {
307 error!("Failed to remove PID file: {}", e);
308 }
309
310 Ok(())
311 } else {
312 error!("PID file not found");
313 Err(LearnerdError::Daemon("Daemon not running".to_string()))
314 }
315 }
316
317 // TODO (autoparallel): this is actually never really able to be used at the moment.
318 /// Restarts the daemon process with a 1-second delay between stop and start.

Callers 2

daemonFunction · 0.80
restartMethod · 0.80

Calls 1

DaemonClass · 0.85

Tested by

no test coverage detected