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
- 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
- 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 std::fs::File;
use std::io::prelude::*;
use std::process;
pub mod crypto;
pub mod error;
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 {
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) {
if !foreground {
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")
.help("Specifies the location of the PID file")
.takes_value(true)
.value_name("FILE")
.conflicts_with("foreground"),
.value_name("FILE"),
)
.arg(
Arg::with_name("root-cert")

3
tacd/src/main.rs

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

Loading…
Cancel
Save