Browse Source

Allow --pid-file to be used with --foreground

The PID file is now always written whether or not ACMEd is running in
the foreground. Previously, it was written only when running in the
background.
Fix #7
pull/19/head
Rodolphe Breard 5 years ago
parent
commit
9eda92662d
  1. 3
      CHANGELOG.md
  2. 33
      acme_common/src/lib.rs
  3. 3
      acmed/src/main.rs
  4. 3
      tacd/src/main.rs

3
CHANGELOG.md

@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Wildcard certificates are now supported. In the file name, the `*` is replaced by `_`. - Wildcard certificates are now supported. In the file name, the `*` is replaced by `_`.
### Changed
- The PID file is now always written whether or not ACMEd is running in the foreground. Previously, it was written only when running in the background.
### Fixed ### Fixed
- In the directory, the `externalAccountRequired` field is now a boolean instead of a string. - In the directory, the `externalAccountRequired` field is now a boolean instead of a string.

33
acme_common/src/lib.rs

@ -1,9 +1,24 @@
use daemonize::Daemonize; use daemonize::Daemonize;
use std::fs::File;
use std::io::prelude::*;
use std::process;
pub mod crypto; pub mod crypto;
pub mod error; pub mod error;
pub mod logs; pub mod logs;
macro_rules! exit_match {
($e: expr) => {
match $e {
Ok(_) => {}
Err(e) => {
eprintln!("Error: {}", e);
std::process::exit(3);
}
}
};
}
pub fn b64_encode<T: ?Sized + AsRef<[u8]>>(input: &T) -> String { pub fn b64_encode<T: ?Sized + AsRef<[u8]>>(input: &T) -> String {
base64::encode_config(input, base64::URL_SAFE_NO_PAD) base64::encode_config(input, base64::URL_SAFE_NO_PAD)
} }
@ -11,12 +26,16 @@ pub fn b64_encode<T: ?Sized + AsRef<[u8]>>(input: &T) -> String {
pub fn init_server(foreground: bool, pid_file: &str) { pub fn init_server(foreground: bool, pid_file: &str) {
if !foreground { if !foreground {
let daemonize = Daemonize::new().pid_file(pid_file); let daemonize = Daemonize::new().pid_file(pid_file);
match daemonize.start() {
Ok(_) => {}
Err(e) => {
eprintln!("Error: {}", e);
std::process::exit(3);
}
}
exit_match!(daemonize.start());
} else {
exit_match!(write_pid_file(pid_file));
} }
} }
fn write_pid_file(pid_file: &str) -> Result<(), error::Error> {
let data = format!("{}\n", process::id()).into_bytes();
let mut file = File::create(pid_file)?;
file.write_all(&data)?;
file.sync_all()?;
Ok(())
}

3
acmed/src/main.rs

@ -86,8 +86,7 @@ fn main() {
.long("pid-file") .long("pid-file")
.help("Specifies the location of the PID file") .help("Specifies the location of the PID file")
.takes_value(true) .takes_value(true)
.value_name("FILE")
.conflicts_with("foreground"),
.value_name("FILE"),
) )
.arg( .arg(
Arg::with_name("root-cert") Arg::with_name("root-cert")

3
tacd/src/main.rs

@ -128,8 +128,7 @@ fn main() {
.long("pid-file") .long("pid-file")
.help("Specifies the location of the PID file") .help("Specifies the location of the PID file")
.takes_value(true) .takes_value(true)
.value_name("FILE")
.conflicts_with("foreground"),
.value_name("FILE"),
) )
.get_matches(); .get_matches();

Loading…
Cancel
Save