Browse Source

Move the daemonize role to acme_common

pull/5/head
Rodolphe Breard 6 years ago
parent
commit
d549c3db5a
  1. 1
      acme_common/Cargo.toml
  2. 15
      acme_common/src/lib.rs
  3. 1
      acmed/Cargo.toml
  4. 17
      acmed/src/main.rs

1
acme_common/Cargo.toml

@ -13,6 +13,7 @@ name = "acme_common"
[dependencies] [dependencies]
base64 = "0.10" base64 = "0.10"
daemonize = "0.4"
handlebars = "2.0.0-beta.1" handlebars = "2.0.0-beta.1"
http_req = "0.4" http_req = "0.4"
openssl = "0.10" openssl = "0.10"

15
acme_common/src/lib.rs

@ -1,6 +1,21 @@
use daemonize::Daemonize;
pub mod error; pub mod error;
pub mod gen; pub mod gen;
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)
} }
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);
}
}
}
}

1
acmed/Cargo.toml

@ -14,7 +14,6 @@ build = "build.rs"
[dependencies] [dependencies]
acme_common = { path = "../acme_common" } acme_common = { path = "../acme_common" }
clap = "2.32" clap = "2.32"
daemonize = "0.4"
env_logger = "0.6" env_logger = "0.6"
handlebars = "2.0.0-beta.1" handlebars = "2.0.0-beta.1"
http_req = "0.4" http_req = "0.4"

17
acmed/src/main.rs

@ -1,6 +1,6 @@
use crate::main_event_loop::MainEventLoop; use crate::main_event_loop::MainEventLoop;
use acme_common::init_server;
use clap::{App, Arg}; use clap::{App, Arg};
use daemonize::Daemonize;
use log::{error, LevelFilter}; use log::{error, LevelFilter};
mod acme_proto; mod acme_proto;
@ -92,17 +92,10 @@ fn main() {
} }
}; };
if !matches.is_present("foregroung") {
let pid_file = matches.value_of("pid-file").unwrap_or(DEFAULT_PID_FILE);
let daemonize = Daemonize::new().pid_file(pid_file);
match daemonize.start() {
Ok(_) => {}
Err(e) => {
eprintln!("Error: {}", e);
std::process::exit(3);
}
}
}
init_server(
matches.is_present("foregroung"),
matches.value_of("pid-file").unwrap_or(DEFAULT_PID_FILE),
);
let config_file = matches.value_of("config").unwrap_or(DEFAULT_CONFIG_FILE); let config_file = matches.value_of("config").unwrap_or(DEFAULT_CONFIG_FILE);
let mut srv = match MainEventLoop::new(&config_file) { let mut srv = match MainEventLoop::new(&config_file) {

Loading…
Cancel
Save