From 945a28784144e4b0f047bcd0c8235d9b07c241ba Mon Sep 17 00:00:00 2001 From: networkException Date: Mon, 24 Feb 2025 00:17:16 +0100 Subject: [PATCH] Dependencies+Main: Add sd-notify and idle feature back This patch reverts 6959e6c3a63977c242bc13efeef6802aeef694db, 32a24924258bf72864c8e8bb226dc0a5ceee2c50 and 7f7b6b4e29032ba83edc744ff337ab7d40e5703b on top of the current tree, adding back their features. --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/main.rs | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 9c3fdd9..c8fc5ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -288,6 +288,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "sd-notify" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b943eadf71d8b69e661330cb0e2656e31040acf21ee7708e2c238a0ec6af2bf4" +dependencies = [ + "libc", +] + [[package]] name = "secrets-file-builder" version = "0.6.0" @@ -295,6 +304,7 @@ dependencies = [ "anyhow", "clap", "handlebars", + "sd-notify", "serde_json", "url-escape", ] diff --git a/Cargo.toml b/Cargo.toml index ca9db19..0f2df00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,5 +12,6 @@ repository = "https://git.nwex.de/networkException/secrets-file-builder" anyhow = "1.0.88" clap = { version = "4.5.17", features = ["derive"] } handlebars = "5.1.0" +sd-notify = "0.4.5" serde_json = "1.0.114" url-escape = "0.1.1" diff --git a/src/main.rs b/src/main.rs index 7984e02..3c9601d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::env; use std::fs; use std::path::PathBuf; +use std::thread; use anyhow::Result; @@ -8,6 +9,8 @@ use clap::Parser; use serde_json::{Map, Value}; use url_escape; +use sd_notify::NotifyState; + use handlebars::{Context, Handlebars, Helper, HelperResult, JsonRender, Output, RenderContext, RenderErrorReason}; #[derive(clap::Parser)] @@ -18,12 +21,18 @@ struct Arguments { /// The path to write the built secret file to output_path: PathBuf, + + /// If the process should keep running without doing anything. This is used to keep a systemd service + /// running this and the associated RuntimeDirectory alive. + #[clap(long, default_value_t = false)] + idle: bool, } fn main() -> Result<()> { let Arguments { contents_path, output_path, + idle, } = Arguments::parse(); let mut handlebars = Handlebars::new(); @@ -96,5 +105,13 @@ fn main() -> Result<()> { println!("Wrote secret file to '{}'", output_path.to_string_lossy()); + sd_notify::notify(true, &[NotifyState::Ready])?; + + if idle { + loop { + thread::park(); + } + } + Ok(()) }