|
|
@ -1,4 +1,5 @@ |
|
|
|
use clap::{App, Arg};
|
|
|
|
use daemonize::Daemonize;
|
|
|
|
use log::{error, LevelFilter};
|
|
|
|
|
|
|
|
mod acmed;
|
|
|
@ -10,6 +11,7 @@ mod logs; |
|
|
|
mod storage;
|
|
|
|
|
|
|
|
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_ACCOUNTS_DIR: &str = "/etc/acmed/accounts";
|
|
|
|
pub const DEFAULT_CERT_DIR: &str = "/etc/acmed/certs";
|
|
|
@ -31,14 +33,14 @@ fn main() { |
|
|
|
Arg::with_name("config")
|
|
|
|
.short("c")
|
|
|
|
.long("config")
|
|
|
|
.help("Specify an alternative configuration file.")
|
|
|
|
.help("Specify an alternative configuration file")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("FILE"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("log-level")
|
|
|
|
.long("log-level")
|
|
|
|
.help("Specify the log level.")
|
|
|
|
.help("Specify the log level")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("LEVEL")
|
|
|
|
.possible_values(&["error", "warn", "info", "debug", "trace"]),
|
|
|
@ -46,15 +48,30 @@ fn main() { |
|
|
|
.arg(
|
|
|
|
Arg::with_name("to-syslog")
|
|
|
|
.long("log-syslog")
|
|
|
|
.help("Send log messages via syslog.")
|
|
|
|
.help("Sends log messages via syslog")
|
|
|
|
.conflicts_with("to-stderr"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("to-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"),
|
|
|
|
)
|
|
|
|
.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();
|
|
|
|
|
|
|
|
match logs::set_log_system(
|
|
|
@ -65,10 +82,22 @@ fn main() { |
|
|
|
Ok(_) => {}
|
|
|
|
Err(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 mut srv = match acmed::Acmed::new(&config_file) {
|
|
|
|
Ok(s) => s,
|
|
|
|