veilid/veilid-server/src/main.rs

66 lines
1.7 KiB
Rust
Raw Normal View History

2021-11-22 16:28:30 +00:00
#![forbid(unsafe_code)]
2021-12-08 03:09:45 +00:00
#![deny(clippy::all)]
2021-12-09 21:11:52 +00:00
#![deny(unused_must_use)]
2021-11-22 16:28:30 +00:00
mod client_api;
2021-12-11 01:14:33 +00:00
mod client_log_channel;
2022-01-15 23:24:37 +00:00
mod cmdline;
mod server;
2021-11-22 16:28:30 +00:00
mod settings;
2022-01-15 23:24:37 +00:00
#[cfg(unix)]
mod unix;
mod veilid_logs;
#[cfg(windows)]
mod windows;
use async_std::task;
use cfg_if::*;
use server::*;
use veilid_logs::*;
2021-11-22 16:28:30 +00:00
2021-11-29 01:08:50 +00:00
#[allow(clippy::all)]
2021-11-22 16:28:30 +00:00
pub mod veilid_client_capnp {
include!(concat!(env!("OUT_DIR"), "/proto/veilid_client_capnp.rs"));
}
2022-01-15 23:24:37 +00:00
fn main() -> Result<(), String> {
let (settings, matches) = cmdline::process_command_line()?;
2021-11-22 16:28:30 +00:00
2022-01-15 23:24:37 +00:00
// --- Dump Config ---
if matches.occurrences_of("dump-config") != 0 {
//let cfg = config::Config::try_from(&*settingsr);
return serde_yaml::to_writer(std::io::stdout(), &*settings.read())
.map_err(|e| e.to_string());
}
// --- Generate Id ---
if matches.occurrences_of("generate-id") != 0 {
let (key, secret) = veilid_core::generate_secret();
println!("Public: {}\nSecret: {}", key.encode(), secret.encode());
return Ok(());
2021-11-22 16:28:30 +00:00
}
2022-01-15 23:24:37 +00:00
// --- Daemon Mode ----
if settings.read().daemon {
cfg_if! {
if #[cfg(windows)] {
return windows::run_service(settings, matches).map_err(|e| format!("{}", e));
} else if #[cfg(unix)] {
return unix::run_daemon(settings, matches);
}
2021-11-22 16:28:30 +00:00
}
}
2022-01-15 23:24:37 +00:00
// Init combined console/file logger
let logs = VeilidLogs::setup_normal_logs(settings.clone())?;
// --- Normal Startup ---
ctrlc::set_handler(move || {
shutdown();
})
.expect("Error setting Ctrl-C handler");
// Run the server loop
task::block_on(async { run_veilid_server(settings, logs).await })
2021-11-22 16:28:30 +00:00
}