You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.5 KiB
84 lines
2.5 KiB
#[macro_use]
|
|
extern crate serde_derive;
|
|
#[macro_use]
|
|
extern crate log;
|
|
|
|
extern crate actix_web;
|
|
extern crate bytes;
|
|
extern crate clap;
|
|
extern crate env_logger;
|
|
extern crate futures;
|
|
extern crate num_cpus;
|
|
extern crate serde;
|
|
|
|
use clap::{App, Arg};
|
|
|
|
mod server;
|
|
|
|
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
|
|
|
fn main() {
|
|
match std::env::var("RUST_LOG") {
|
|
Ok(_) => (),
|
|
Err(_) => std::env::set_var("RUST_LOG", "actix_web=info"),
|
|
}
|
|
env_logger::init();
|
|
|
|
let args = App::new("Dynamic DNS Server")
|
|
.version(VERSION)
|
|
.author("Drew Short <warrick@sothr.com>")
|
|
.about("Recieve DDNS requests and update cloudflare subdomains")
|
|
.args(&[
|
|
Arg::with_name("config")
|
|
.short("c")
|
|
.long("config")
|
|
.value_name("PATH")
|
|
.default_value("/etc/rsddns/rsddns.yml")
|
|
.help("Set a custom configuration file path.")
|
|
.takes_value(true),
|
|
Arg::with_name("host")
|
|
.short("h")
|
|
.long("host")
|
|
.value_name("HOST")
|
|
.default_value("localhost")
|
|
.help("The address the server listens on.")
|
|
.takes_value(true),
|
|
Arg::with_name("port")
|
|
.short("p")
|
|
.long("port")
|
|
.value_name("PORT")
|
|
.default_value("8080")
|
|
.help("The port to run the server on.")
|
|
.takes_value(true),
|
|
Arg::with_name("workers")
|
|
.short("w")
|
|
.long("workers")
|
|
.value_name("NUMBER")
|
|
.help("The number of workers to serve requests with.")
|
|
.takes_value(true),
|
|
])
|
|
.get_matches();
|
|
|
|
let config: &str = args.value_of("config").unwrap_or("/etc/rsddns/rsddns.yml");
|
|
let host: &str = args.value_of("host").unwrap_or("localhost");
|
|
let port: i32 = args
|
|
.value_of("port")
|
|
.unwrap()
|
|
.parse::<i32>()
|
|
.unwrap_or(8080);
|
|
let workers: usize = match args.value_of("workers") {
|
|
Some(count) => count.parse::<usize>().unwrap_or(num_cpus::get()),
|
|
None => num_cpus::get(),
|
|
};
|
|
|
|
info!(
|
|
"Starting server on {}:{} with workers={} and config {}",
|
|
host, port, workers, config
|
|
);
|
|
|
|
actix_web::server::new(|| server::router::create())
|
|
.workers(workers)
|
|
.bind(format!("{}:{}", host, port))
|
|
.unwrap()
|
|
.run();
|
|
}
|