From 1ae97cd85aec95f6270f853b28e48774cefc6bf6 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 26 Jan 2026 16:17:55 +0000 Subject: feat: add NGIT_LOG_LEVEL configuration option Add proper log level configuration following standard approach: - CLI flag: --log-level - Environment variable: NGIT_LOG_LEVEL - Default: info - Supports simple levels (error, warn, info, debug, trace) - Supports filter expressions (e.g., ngit_grasp=debug,actix_web=info) Configuration is now consistent across all four sources: 1. src/config.rs - Config struct with log_level field 2. docs/reference/configuration.md - Full documentation 3. nix/module.nix - NixOS module with logLevel option 4. .env.example - Example configuration file This replaces the previous RUST_LOG approach with proper integration into the ngit-grasp configuration system, enabling trace logging from CLI, environment variables, or NixOS configuration. --- src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 5e5b83a..105b861 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,8 @@ use std::{path::PathBuf, sync::Arc}; use anyhow::Result; use tokio::signal; -use tracing::{error, info, warn, Level}; -use tracing_subscriber::FmtSubscriber; +use tracing::{error, info, warn}; +use tracing_subscriber::{EnvFilter, FmtSubscriber}; use ngit_grasp::{ config::{Config, DatabaseBackend}, @@ -17,16 +17,16 @@ use ngit_grasp::{ #[tokio::main] async fn main() -> Result<()> { - // Initialize tracing + // Load configuration first (priority: CLI flags > env vars > .env file > defaults) + let config = Config::load()?; + + // Initialize tracing with configured log level let subscriber = FmtSubscriber::builder() - .with_max_level(Level::DEBUG) + .with_env_filter(EnvFilter::new(&config.log_level)) .finish(); tracing::subscriber::set_global_default(subscriber)?; - info!("Starting ngit-grasp with nostr-relay-builder..."); - - // Load configuration (priority: CLI flags > env vars > .env file > defaults) - let config = Config::load()?; + info!("Starting ngit-grasp with log level: {}", config.log_level); // Validate configuration and fail fast on fatal errors // Recoverable issues (e.g., malformed whitelist entries) are logged as warnings -- cgit v1.2.3 From 04056a12110928e406d2aca456fc3169ae39f8ad Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 27 Jan 2026 07:37:35 +0000 Subject: increase git throttle limits to 60/m --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 105b861..6c9da05 100644 --- a/src/main.rs +++ b/src/main.rs @@ -187,8 +187,8 @@ async fn main() -> Result<()> { )); // Create throttle manager for rate limiting remote git servers - // Default: 5 concurrent requests per domain, 30 requests per minute per domain - let throttle_manager = Arc::new(ThrottleManager::new(5, 30)); + // Default: 5 concurrent requests per domain, 60 requests per minute per domain + let throttle_manager = Arc::new(ThrottleManager::new(5, 60)); throttle_manager.set_context(sync_ctx.clone()); throttle_manager.set_git_naughty_list(git_naughty_list.clone()); -- cgit v1.2.3 From e0ad39a489b3398f8208713bf728db0cb11475b0 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 3 Feb 2026 22:22:53 +0000 Subject: Handle SIGTERM for graceful shutdown with systemd Listen for both SIGINT (Ctrl+C) and SIGTERM (systemd) signals to ensure graceful shutdown cleanup runs when stopping the service via systemd. Previously, only SIGINT was handled, causing purgatory state and rejected events cache to be lost on every systemd restart. Now both signals trigger the cleanup code that saves state files and removes placeholder refs. Fixes issue 0f73 --- src/main.rs | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 6c9da05..dd2c903 100644 --- a/src/main.rs +++ b/src/main.rs @@ -207,18 +207,45 @@ async fn main() -> Result<()> { info!("Starting HTTP server on {}", config.bind_address); // Run server until shutdown signal, then cleanup - tokio::select! { - result = http::run_server( - config, - relay_with_db.relay, - relay_with_db.database, - metrics, - purgatory, - ) => { - result? + #[cfg(unix)] + { + use tokio::signal::unix::{signal, SignalKind}; + let mut sigterm = signal(SignalKind::terminate())?; + + tokio::select! { + result = http::run_server( + config, + relay_with_db.relay, + relay_with_db.database, + metrics, + purgatory, + ) => { + result? + } + _ = signal::ctrl_c() => { + info!("Received SIGINT (Ctrl+C), cleaning up..."); + } + _ = sigterm.recv() => { + info!("Received SIGTERM, cleaning up..."); + } } - _ = signal::ctrl_c() => { - info!("Received shutdown signal, cleaning up..."); + } + + #[cfg(not(unix))] + { + tokio::select! { + result = http::run_server( + config, + relay_with_db.relay, + relay_with_db.database, + metrics, + purgatory, + ) => { + result? + } + _ = signal::ctrl_c() => { + info!("Received SIGINT (Ctrl+C), cleaning up..."); + } } } -- cgit v1.2.3