mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-26 00:24:55 +01:00
Also catch SIGQUIT and SIGTERM and clean up properly
This commit is contained in:
parent
200179f621
commit
9fcb7664aa
@ -1,11 +1,13 @@
|
|||||||
use slog::{Drain, Logger};
|
use slog::{Drain, Logger};
|
||||||
use slog_async;
|
use slog_async;
|
||||||
|
use slog_async::AsyncGuard;
|
||||||
use slog_term::{TermDecorator, FullFormat};
|
use slog_term::{TermDecorator, FullFormat};
|
||||||
|
|
||||||
pub fn init() -> Logger {
|
pub fn init() -> (Logger, AsyncGuard) {
|
||||||
let decorator = TermDecorator::new().build();
|
let decorator = TermDecorator::new().build();
|
||||||
let drain = FullFormat::new(decorator).build().fuse();
|
let drain = FullFormat::new(decorator).build().fuse();
|
||||||
let drain = slog_async::Async::new(drain).build().fuse();
|
let (drain, guard) = slog_async::Async::new(drain).build_with_guard();
|
||||||
|
let drain = drain.fuse();
|
||||||
|
|
||||||
return slog::Logger::root(drain, o!());
|
return (slog::Logger::root(drain, o!()), guard);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,8 @@ fn main() {
|
|||||||
// on.
|
// on.
|
||||||
// TODO: Now would be a really good time to close stdin/out and move logging to syslog
|
// TODO: Now would be a really good time to close stdin/out and move logging to syslog
|
||||||
// Log is in an Arc so we can do very cheap clones in closures.
|
// Log is in an Arc so we can do very cheap clones in closures.
|
||||||
let log = Arc::new(log::init());
|
let (log, guard) = log::init();
|
||||||
|
let log = Arc::new(log);
|
||||||
info!(log, "Starting");
|
info!(log, "Starting");
|
||||||
|
|
||||||
match maybe(matches, log.clone()) {
|
match maybe(matches, log.clone()) {
|
||||||
@ -125,9 +126,8 @@ fn main() {
|
|||||||
retval = -1;
|
retval = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
drop(guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::process::exit(retval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returning a `Result` from `main` allows us to use the `?` shorthand.
|
// Returning a `Result` from `main` allows us to use the `?` shorthand.
|
||||||
|
@ -27,11 +27,15 @@ pub fn serve_api_connections(log: Arc<Logger>, config: Config, db: Databases, nw
|
|||||||
-> Result<(), Error>
|
-> Result<(), Error>
|
||||||
{
|
{
|
||||||
let signal = Box::pin(async {
|
let signal = Box::pin(async {
|
||||||
|
use signal_hook::consts::signal::*;
|
||||||
let (tx, mut rx) = UnixStream::pair()?;
|
let (tx, mut rx) = UnixStream::pair()?;
|
||||||
// Initialize signal handler.
|
// Initialize signal handler.
|
||||||
// We currently only care about Ctrl-C so SIGINT it is.
|
// We currently only care about Ctrl-C so SIGINT it is.
|
||||||
// TODO: Make this do SIGHUP and a few others too. (By cloning the tx end of the pipe)
|
// TODO: Make this do SIGHUP and a few others too. (By cloning the tx end of the pipe)
|
||||||
sigpipe::register(signal_hook::consts::SIGINT, tx.as_raw_fd())?;
|
let fd = tx.as_raw_fd();
|
||||||
|
sigpipe::register(SIGINT, fd)?;
|
||||||
|
sigpipe::register(SIGQUIT, fd)?;
|
||||||
|
sigpipe::register(SIGTERM, fd)?;
|
||||||
// When a signal is received this future can complete and read a byte from the underlying
|
// When a signal is received this future can complete and read a byte from the underlying
|
||||||
// socket — the actual data is discarded but the act of being able to receive data tells us
|
// socket — the actual data is discarded but the act of being able to receive data tells us
|
||||||
// that we received a SIGINT.
|
// that we received a SIGINT.
|
||||||
|
Loading…
Reference in New Issue
Block a user