bin/proxmox-backup-api.rs: improve error handling
This commit is contained in:
parent
4223d9f800
commit
aa5a4060ab
|
@ -6,6 +6,7 @@ use proxmox_backup::api::config::*;
|
||||||
use proxmox_backup::server::rest::*;
|
use proxmox_backup::server::rest::*;
|
||||||
use proxmox_backup::auth_helpers::*;
|
use proxmox_backup::auth_helpers::*;
|
||||||
|
|
||||||
|
use failure::*;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
use futures::future::Future;
|
use futures::future::Future;
|
||||||
|
@ -14,23 +15,28 @@ use hyper;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
|
if let Err(err) = run() {
|
||||||
|
eprintln!("Error: {}", err);
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run() -> Result<(), Error> {
|
||||||
|
|
||||||
if let Err(err) = syslog::init(
|
if let Err(err) = syslog::init(
|
||||||
syslog::Facility::LOG_DAEMON,
|
syslog::Facility::LOG_DAEMON,
|
||||||
log::LevelFilter::Info,
|
log::LevelFilter::Info,
|
||||||
Some("proxmox-backup-api")) {
|
Some("proxmox-backup-api")) {
|
||||||
eprintln!("unable to inititialize syslog: {}", err);
|
bail!("unable to inititialize syslog - {}", err);
|
||||||
std::process::exit(-1);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Err(err) = generate_auth_key() {
|
if let Err(err) = generate_auth_key() {
|
||||||
eprintln!("unable to generate auth key: {}", err);
|
bail!("unable to generate auth key - {}", err);
|
||||||
std::process::exit(-1);
|
|
||||||
}
|
}
|
||||||
let _ = private_auth_key(); // load with lazy_static
|
let _ = private_auth_key(); // load with lazy_static
|
||||||
|
|
||||||
if let Err(err) = generate_csrf_key() {
|
if let Err(err) = generate_csrf_key() {
|
||||||
eprintln!("unable to generate csrf key: {}", err);
|
bail!("unable to generate csrf key - {}", err);
|
||||||
std::process::exit(-1);
|
|
||||||
}
|
}
|
||||||
let _ = csrf_secret(); // load with lazy_static
|
let _ = csrf_secret(); // load with lazy_static
|
||||||
|
|
||||||
|
@ -49,7 +55,8 @@ fn main() {
|
||||||
.serve(rest_server)
|
.serve(rest_server)
|
||||||
.map_err(|e| eprintln!("server error: {}", e));
|
.map_err(|e| eprintln!("server error: {}", e));
|
||||||
|
|
||||||
|
|
||||||
// Run this server for... forever!
|
// Run this server for... forever!
|
||||||
hyper::rt::run(server);
|
hyper::rt::run(server);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue