2018-09-29 09:54:16 +02:00
|
|
|
extern crate actix;
|
2019-07-12 07:28:46 +02:00
|
|
|
extern crate env_logger;
|
2018-09-29 09:54:16 +02:00
|
|
|
|
2018-10-03 13:21:21 +02:00
|
|
|
extern crate rsidm;
|
2019-07-15 01:15:25 +02:00
|
|
|
extern crate structopt;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2019-05-08 02:39:46 +02:00
|
|
|
|
2018-11-26 07:13:22 +01:00
|
|
|
use rsidm::config::Configuration;
|
2019-07-15 01:15:25 +02:00
|
|
|
use rsidm::core::{backup_server_core, create_server_core, restore_server_core};
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct ServerOpt {
|
|
|
|
#[structopt(short = "d", long = "debug")]
|
|
|
|
debug: bool,
|
|
|
|
#[structopt(parse(from_os_str), short = "D", long = "db_path")]
|
|
|
|
db_path: PathBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct BackupOpt {
|
|
|
|
#[structopt(parse(from_os_str))]
|
|
|
|
path: PathBuf,
|
|
|
|
#[structopt(flatten)]
|
|
|
|
serveropts: ServerOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct RestoreOpt {
|
|
|
|
#[structopt(parse(from_os_str))]
|
|
|
|
path: PathBuf,
|
|
|
|
#[structopt(flatten)]
|
|
|
|
serveropts: ServerOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
enum Opt {
|
|
|
|
#[structopt(name = "server")]
|
|
|
|
Server(ServerOpt),
|
|
|
|
#[structopt(name = "backup")]
|
|
|
|
Backup(BackupOpt),
|
|
|
|
#[structopt(name = "restore")]
|
|
|
|
Restore(RestoreOpt),
|
|
|
|
}
|
2018-11-11 22:59:09 +01:00
|
|
|
|
2018-09-29 09:54:16 +02:00
|
|
|
fn main() {
|
2019-07-15 01:15:25 +02:00
|
|
|
// Read cli args, determine if we should backup/restore
|
|
|
|
let opt = Opt::from_args();
|
|
|
|
|
2019-07-12 07:28:46 +02:00
|
|
|
// Read our config (if any)
|
2019-07-15 01:15:25 +02:00
|
|
|
let mut config = Configuration::new();
|
|
|
|
// Apply any cli overrides?
|
2019-07-12 07:28:46 +02:00
|
|
|
|
|
|
|
// Configure the server logger. This could be adjusted based on what config
|
|
|
|
// says.
|
|
|
|
::std::env::set_var("RUST_LOG", "actix_web=info,rsidm=info");
|
|
|
|
env_logger::init();
|
|
|
|
|
2019-07-15 01:15:25 +02:00
|
|
|
match opt {
|
|
|
|
Opt::Server(sopt) => {
|
|
|
|
info!("Running in server mode ...");
|
|
|
|
|
|
|
|
config.update_db_path(&sopt.db_path);
|
|
|
|
|
|
|
|
let sys = actix::System::new("rsidm-server");
|
|
|
|
create_server_core(config);
|
|
|
|
let _ = sys.run();
|
|
|
|
}
|
|
|
|
Opt::Backup(bopt) => {
|
|
|
|
info!("Running in backup mode ...");
|
|
|
|
|
|
|
|
config.update_db_path(&bopt.serveropts.db_path);
|
|
|
|
|
|
|
|
let p = match bopt.path.to_str() {
|
|
|
|
Some(p) => p,
|
|
|
|
None => {
|
|
|
|
error!("Invalid backup path");
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
backup_server_core(config, p);
|
|
|
|
}
|
|
|
|
Opt::Restore(ropt) => {
|
|
|
|
info!("Running in restore mode ...");
|
|
|
|
|
|
|
|
config.update_db_path(&ropt.serveropts.db_path);
|
2018-09-29 09:54:16 +02:00
|
|
|
|
2019-07-15 01:15:25 +02:00
|
|
|
let p = match ropt.path.to_str() {
|
|
|
|
Some(p) => p,
|
|
|
|
None => {
|
|
|
|
error!("Invalid restore path");
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
restore_server_core(config, p);
|
|
|
|
}
|
|
|
|
}
|
2018-09-29 09:54:16 +02:00
|
|
|
}
|