From 52973b4b9e313d87b6148a55a11ccacfdaeb8a3d Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Fri, 29 May 2020 13:12:30 +0200 Subject: [PATCH] Remove the PID file after exit Fix #25 --- acme_common/src/lib.rs | 9 ++++++++- acmed/src/main.rs | 3 ++- tacd/src/main.rs | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/acme_common/src/lib.rs b/acme_common/src/lib.rs index 8578322..147945d 100644 --- a/acme_common/src/lib.rs +++ b/acme_common/src/lib.rs @@ -1,7 +1,7 @@ use daemonize::Daemonize; use std::fs::File; use std::io::prelude::*; -use std::process; +use std::{fs, process}; pub mod crypto; pub mod error; @@ -57,6 +57,13 @@ fn write_pid_file(pid_file: &str) -> Result<(), error::Error> { Ok(()) } +pub fn clean_pid_file(pid_file: Option<&str>) -> Result<(), error::Error> { + if let Some(f) = pid_file { + fs::remove_file(f)?; + } + Ok(()) +} + #[cfg(test)] mod tests { use super::to_idna; diff --git a/acmed/src/main.rs b/acmed/src/main.rs index 87c4660..1a5c657 100644 --- a/acmed/src/main.rs +++ b/acmed/src/main.rs @@ -1,5 +1,5 @@ use crate::main_event_loop::MainEventLoop; -use acme_common::init_server; +use acme_common::{clean_pid_file, init_server}; use clap::{App, Arg}; use log::error; @@ -126,6 +126,7 @@ fn main() { Ok(s) => s, Err(e) => { error!("{}", e); + let _ = clean_pid_file(matches.value_of("pid-file")); std::process::exit(1); } }; diff --git a/tacd/src/main.rs b/tacd/src/main.rs index 1f59982..cc772aa 100644 --- a/tacd/src/main.rs +++ b/tacd/src/main.rs @@ -3,7 +3,7 @@ mod openssl_server; use crate::openssl_server::start as server_start; use acme_common::crypto::X509Certificate; use acme_common::error::Error; -use acme_common::to_idna; +use acme_common::{clean_pid_file, to_idna}; use clap::{App, Arg, ArgMatches}; use log::{debug, error, info}; use std::fs::File; @@ -151,6 +151,7 @@ fn main() { Ok(_) => {} Err(e) => { error!("{}", e); + let _ = clean_pid_file(matches.value_of("pid-file")); std::process::exit(1); } };