use crate::process::pid::pid_utils::delete_pid_file_if_my_process;
use crate::process::{write_pid, PidError};
use log::warn;
use std::path::PathBuf;
#[derive(Debug)]
pub struct PidFileGuard {
pid_file_path: PathBuf,
}
impl Drop for PidFileGuard {
fn drop(&mut self) {
if let Err(e) = delete_pid_file_if_my_process(&self.pid_file_path) {
warn!("Failed to delete PID file: {:#}", e);
}
}
}
impl PidFileGuard {
pub fn new(pid_file_path: PathBuf) -> Result<Self, PidError> {
write_pid(&pid_file_path)?;
Ok(Self { pid_file_path })
}
}