Disable server auto-restart

This commit is contained in:
Roman Zeyde 2018-06-14 20:51:00 +03:00
parent 46bda14ddf
commit 7bdb1491ae
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with 2 additions and 45 deletions

View File

@ -2,7 +2,6 @@ extern crate electrs;
extern crate error_chain;
use error_chain::ChainedError;
use std::thread;
use std::time::Duration;
use electrs::{app::App,
@ -46,43 +45,9 @@ fn run_server(config: &Config) -> Result<()> {
Ok(())
}
struct Repeat {
do_restart: bool,
iter_count: usize,
}
impl Repeat {
fn new(config: &Config) -> Repeat {
Repeat {
do_restart: config.restart,
iter_count: 0,
}
}
}
impl Iterator for Repeat {
type Item = ();
fn next(&mut self) -> Option<()> {
self.iter_count += 1;
if self.iter_count == 1 {
return Some(()); // don't sleep before 1st iteration
}
thread::sleep(Duration::from_secs(1));
if self.do_restart {
Some(())
} else {
None
}
}
}
fn main() {
let config = Config::from_args();
for _ in Repeat::new(&config) {
match run_server(&config) {
Ok(_) => break,
Err(e) => eprintln!("{}", e.display_chain()),
}
if let Err(e) = run_server(&config) {
eprintln!("server failed: {}", e.display_chain());
}
}

View File

@ -8,7 +8,6 @@ use std::net::SocketAddr;
pub struct Config {
pub log_file: String,
pub log_level: simplelog::LevelFilter,
pub restart: bool,
pub network_type: Network, // bitcoind JSONRPC endpoint
pub db_path: String, // RocksDB directory path
pub rpc_addr: SocketAddr, // for serving Electrum clients
@ -19,7 +18,6 @@ impl Config {
pub fn from_args() -> Config {
let mut testnet = false;
let mut verbose = false;
let mut restart = false;
let mut log_file = "".to_owned();
let mut db_dir = "./db".to_owned();
{
@ -35,11 +33,6 @@ impl Config {
StoreTrue,
"More verbose logging to stderr",
);
parser.refer(&mut restart).add_option(
&["--restart"],
StoreTrue,
"Restart the server in case of a recoverable error",
);
parser.refer(&mut log_file).add_option(
&["-l", "--log-file"],
Store,
@ -63,7 +56,6 @@ impl Config {
} else {
simplelog::LevelFilter::Info
},
restart,
network_type,
db_path: match network_type {
Network::Mainnet => format!("{}/mainnet", db_dir),