mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-12-22 19:53:49 +01:00
Properly stop api server
This commit is contained in:
parent
be73385758
commit
7bdbdac86b
@ -175,8 +175,11 @@ fn maybe(matches: clap::ArgMatches, log: Arc<Logger>) -> Result<(), Error> {
|
||||
// TODO: Spawn api connections on their own (non-main) thread, use the main thread to
|
||||
// handle signals (a cli if stdin is not closed?) and make it stop and clean up all threads
|
||||
// when bffh should exit
|
||||
server::serve_api_connections(log.clone(), config, db, network)
|
||||
// Signal is dropped here, stopping all executor threads as well.
|
||||
let r = server::serve_api_connections(log.clone(), config, db, network);
|
||||
|
||||
signal.try_send(());
|
||||
std::mem::drop(signal);
|
||||
return r;
|
||||
});
|
||||
|
||||
return r;
|
||||
|
@ -54,6 +54,7 @@ pub fn serve_api_connections(log: Arc<Logger>, config: Settings, db: Databases,
|
||||
.map(|l| {
|
||||
let addr = l.address.clone();
|
||||
let port = l.port.unwrap_or(config::DEFAULT_PORT);
|
||||
info!(&log, "Binding to {} port {}.", l.address.as_str(), &port);
|
||||
TcpListener::bind((l.address.as_str(), port))
|
||||
// If the bind errors, include the address so we can log it
|
||||
// Since this closure is lazy we need to have a cloned addr
|
||||
@ -124,6 +125,8 @@ pub fn serve_api_connections(log: Arc<Logger>, config: Settings, db: Databases,
|
||||
return LoopResult::Continue;
|
||||
});
|
||||
|
||||
info!(&log, "Started");
|
||||
|
||||
// Check each signal as it arrives
|
||||
let handle_signals = signal.map(|r| { r.unwrap() }).into_stream();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user