|
@ -1,4 +1,5 @@ |
|
|
use clap::{App, Arg};
|
|
|
use clap::{App, Arg};
|
|
|
|
|
|
use daemonize::Daemonize;
|
|
|
use log::{error, LevelFilter};
|
|
|
use log::{error, LevelFilter};
|
|
|
|
|
|
|
|
|
mod acmed;
|
|
|
mod acmed;
|
|
@ -10,6 +11,7 @@ mod logs; |
|
|
mod storage;
|
|
|
mod storage;
|
|
|
|
|
|
|
|
|
pub const APP_NAME: &str = "acmed";
|
|
|
pub const APP_NAME: &str = "acmed";
|
|
|
|
|
|
pub const DEFAULT_PID_FILE: &str = "/var/run/admed.pid";
|
|
|
pub const DEFAULT_CONFIG_FILE: &str = "/etc/acmed/acmed.toml";
|
|
|
pub const DEFAULT_CONFIG_FILE: &str = "/etc/acmed/acmed.toml";
|
|
|
pub const DEFAULT_ACCOUNTS_DIR: &str = "/etc/acmed/accounts";
|
|
|
pub const DEFAULT_ACCOUNTS_DIR: &str = "/etc/acmed/accounts";
|
|
|
pub const DEFAULT_CERT_DIR: &str = "/etc/acmed/certs";
|
|
|
pub const DEFAULT_CERT_DIR: &str = "/etc/acmed/certs";
|
|
@ -31,14 +33,14 @@ fn main() { |
|
|
Arg::with_name("config")
|
|
|
Arg::with_name("config")
|
|
|
.short("c")
|
|
|
.short("c")
|
|
|
.long("config")
|
|
|
.long("config")
|
|
|
.help("Specify an alternative configuration file.")
|
|
|
|
|
|
|
|
|
.help("Specify an alternative configuration file")
|
|
|
.takes_value(true)
|
|
|
.takes_value(true)
|
|
|
.value_name("FILE"),
|
|
|
.value_name("FILE"),
|
|
|
)
|
|
|
)
|
|
|
.arg(
|
|
|
.arg(
|
|
|
Arg::with_name("log-level")
|
|
|
Arg::with_name("log-level")
|
|
|
.long("log-level")
|
|
|
.long("log-level")
|
|
|
.help("Specify the log level.")
|
|
|
|
|
|
|
|
|
.help("Specify the log level")
|
|
|
.takes_value(true)
|
|
|
.takes_value(true)
|
|
|
.value_name("LEVEL")
|
|
|
.value_name("LEVEL")
|
|
|
.possible_values(&["error", "warn", "info", "debug", "trace"]),
|
|
|
.possible_values(&["error", "warn", "info", "debug", "trace"]),
|
|
@ -46,15 +48,30 @@ fn main() { |
|
|
.arg(
|
|
|
.arg(
|
|
|
Arg::with_name("to-syslog")
|
|
|
Arg::with_name("to-syslog")
|
|
|
.long("log-syslog")
|
|
|
.long("log-syslog")
|
|
|
.help("Send log messages via syslog.")
|
|
|
|
|
|
|
|
|
.help("Sends log messages via syslog")
|
|
|
.conflicts_with("to-stderr"),
|
|
|
.conflicts_with("to-stderr"),
|
|
|
)
|
|
|
)
|
|
|
.arg(
|
|
|
.arg(
|
|
|
Arg::with_name("to-stderr")
|
|
|
Arg::with_name("to-stderr")
|
|
|
.long("log-stderr")
|
|
|
.long("log-stderr")
|
|
|
.help("Print log messages to the standard error output.")
|
|
|
|
|
|
|
|
|
.help("Prints log messages to the standard error output")
|
|
|
.conflicts_with("log-syslog"),
|
|
|
.conflicts_with("log-syslog"),
|
|
|
)
|
|
|
)
|
|
|
|
|
|
.arg(
|
|
|
|
|
|
Arg::with_name("foregroung")
|
|
|
|
|
|
.short("f")
|
|
|
|
|
|
.long("foregroung")
|
|
|
|
|
|
.help("Runs in the foregroung")
|
|
|
|
|
|
.conflicts_with("to-stderr"),
|
|
|
|
|
|
)
|
|
|
|
|
|
.arg(
|
|
|
|
|
|
Arg::with_name("pid-file")
|
|
|
|
|
|
.long("pid-file")
|
|
|
|
|
|
.help("Specifies the location of the PID file")
|
|
|
|
|
|
.takes_value(true)
|
|
|
|
|
|
.value_name("FILE")
|
|
|
|
|
|
.conflicts_with("foregroung"),
|
|
|
|
|
|
)
|
|
|
.get_matches();
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
|
match logs::set_log_system(
|
|
|
match logs::set_log_system(
|
|
@ -65,10 +82,22 @@ fn main() { |
|
|
Ok(_) => {}
|
|
|
Ok(_) => {}
|
|
|
Err(e) => {
|
|
|
Err(e) => {
|
|
|
eprintln!("Error: {}", e);
|
|
|
eprintln!("Error: {}", e);
|
|
|
std::process::exit(1);
|
|
|
|
|
|
|
|
|
std::process::exit(2);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 acmed::Acmed::new(&config_file) {
|
|
|
let mut srv = match acmed::Acmed::new(&config_file) {
|
|
|
Ok(s) => s,
|
|
|
Ok(s) => s,
|
|
|