Browse Source

Remove the PID file after exit

Fix #25
pull/31/head
Rodolphe Breard 5 years ago
parent
commit
52973b4b9e
  1. 9
      acme_common/src/lib.rs
  2. 3
      acmed/src/main.rs
  3. 3
      tacd/src/main.rs

9
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;

3
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);
}
};

3
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);
}
};

Loading…
Cancel
Save