From 71157983e36471d6434f50d8420857e90c9252e6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 14 Dec 2023 15:51:11 +0100 Subject: [PATCH] Allow the daemon to notify the parent that it's ready --- magic-nix-cache/src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/magic-nix-cache/src/main.rs b/magic-nix-cache/src/main.rs index 86abd29..a05774f 100644 --- a/magic-nix-cache/src/main.rs +++ b/magic-nix-cache/src/main.rs @@ -2,7 +2,6 @@ asm_sub_register, deprecated, missing_abi, - unsafe_code, unused_macros, unused_must_use, unused_unsafe @@ -24,6 +23,7 @@ use std::collections::HashSet; use std::fs::{self, create_dir_all, OpenOptions}; use std::io::Write; use std::net::SocketAddr; +use std::os::fd::FromRawFd; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -100,6 +100,10 @@ struct Args { /// Whether to use the FlakeHub binary cache. #[arg(long)] use_flakehub: bool, + + /// File descriptor on which to send startup notification. + #[arg(long)] + notify_fd: Option, } /// The global server state. @@ -271,6 +275,12 @@ async fn main_cli() { let app = app.layer(Extension(state.clone())); tracing::info!("Listening on {}", args.listen); + + if let Some(notify_fd) = args.notify_fd { + let mut f = unsafe { std::fs::File::from_raw_fd(notify_fd) }; + write!(&mut f, "INIT\n").unwrap(); + } + let ret = axum::Server::bind(&args.listen) .serve(app.into_make_service()) .with_graceful_shutdown(async move { @@ -332,6 +342,7 @@ fn init_logging() { }); tracing_subscriber::fmt() + .with_writer(std::io::stderr) .pretty() .with_env_filter(filter) .init();