mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
Small cleanup of SIGINT and SIGTERM handler (#1535)
This commit is contained in:
parent
9aed3b9c7f
commit
8bef9bef02
1 changed files with 7 additions and 10 deletions
|
@ -37,9 +37,9 @@ fn start_server(config: servers::ServerConfig) {
|
||||||
// Just kill process for now, otherwise the process
|
// Just kill process for now, otherwise the process
|
||||||
// hangs around until sigint because the API server
|
// hangs around until sigint because the API server
|
||||||
// currently has no shutdown facility
|
// currently has no shutdown facility
|
||||||
println!("Shutting down...");
|
warn!(LOGGER, "Shutting down...");
|
||||||
thread::sleep(Duration::from_millis(1000));
|
thread::sleep(Duration::from_millis(1000));
|
||||||
println!("Shutdown complete.");
|
warn!(LOGGER, "Shutdown complete.");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,33 +47,30 @@ fn start_server_tui(config: servers::ServerConfig) {
|
||||||
// Run the UI controller.. here for now for simplicity to access
|
// Run the UI controller.. here for now for simplicity to access
|
||||||
// everything it might need
|
// everything it might need
|
||||||
if config.run_tui.is_some() && config.run_tui.unwrap() {
|
if config.run_tui.is_some() && config.run_tui.unwrap() {
|
||||||
println!("Starting GRIN in UI mode...");
|
warn!(LOGGER, "Starting GRIN in UI mode...");
|
||||||
servers::Server::start(config, |serv: Arc<servers::Server>| {
|
servers::Server::start(config, |serv: Arc<servers::Server>| {
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
let r = running.clone();
|
|
||||||
let _ = thread::Builder::new()
|
let _ = thread::Builder::new()
|
||||||
.name("ui".to_string())
|
.name("ui".to_string())
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
let mut controller = ui::Controller::new().unwrap_or_else(|e| {
|
let mut controller = ui::Controller::new().unwrap_or_else(|e| {
|
||||||
panic!("Error loading UI controller: {}", e);
|
panic!("Error loading UI controller: {}", e);
|
||||||
});
|
});
|
||||||
controller.run(serv.clone(), r);
|
controller.run(serv.clone(), running);
|
||||||
});
|
});
|
||||||
ctrlc::set_handler(move || {
|
|
||||||
running.store(false, Ordering::SeqCst);
|
|
||||||
}).expect("Error setting Ctrl-C handler");
|
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
} else {
|
} else {
|
||||||
|
warn!(LOGGER, "Starting GRIN w/o UI...");
|
||||||
servers::Server::start(config, |serv: Arc<servers::Server>| {
|
servers::Server::start(config, |serv: Arc<servers::Server>| {
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
let r = running.clone();
|
let r = running.clone();
|
||||||
ctrlc::set_handler(move || {
|
ctrlc::set_handler(move || {
|
||||||
r.store(false, Ordering::SeqCst);
|
r.store(false, Ordering::SeqCst);
|
||||||
}).expect("Error setting Ctrl-C handler");
|
}).expect("Error setting handler for both SIGINT (Ctrl+C) and SIGTERM (kill)");
|
||||||
while running.load(Ordering::SeqCst) {
|
while running.load(Ordering::SeqCst) {
|
||||||
thread::sleep(Duration::from_secs(1));
|
thread::sleep(Duration::from_secs(1));
|
||||||
}
|
}
|
||||||
warn!(LOGGER, "Received SIGINT (Ctrl+C).");
|
warn!(LOGGER, "Received SIGINT (Ctrl+C) or SIGTERM (kill).");
|
||||||
serv.stop();
|
serv.stop();
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue