From 14a9e9e7e323a1bd86072b21f7563dfe6f65d634 Mon Sep 17 00:00:00 2001 From: Razvan Dimescu Date: Fri, 20 Mar 2026 14:26:56 +0200 Subject: [PATCH] add numa service restart command Kills the running process and lets launchd/systemd respawn it with the updated binary. DNS stays configured throughout. Co-Authored-By: Claude Opus 4.6 --- src/main.rs | 8 +++++--- src/system_dns.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5188071..ef85cbb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,8 +14,8 @@ use numa::override_store::OverrideStore; use numa::query_log::QueryLog; use numa::stats::ServerStats; use numa::system_dns::{ - discover_system_dns, install_service, install_system_dns, service_status, uninstall_service, - uninstall_system_dns, + discover_system_dns, install_service, install_system_dns, restart_service, service_status, + uninstall_service, uninstall_system_dns, }; #[tokio::main] @@ -41,9 +41,10 @@ async fn main() -> numa::Result<()> { return match sub.as_str() { "start" => install_service().map_err(|e| e.into()), "stop" => uninstall_service().map_err(|e| e.into()), + "restart" => restart_service().map_err(|e| e.into()), "status" => service_status().map_err(|e| e.into()), _ => { - eprintln!("Usage: numa service "); + eprintln!("Usage: numa service "); Ok(()) } }; @@ -57,6 +58,7 @@ async fn main() -> numa::Result<()> { eprintln!(" uninstall Restore original system DNS settings"); eprintln!(" service start Install as system service (auto-start on boot)"); eprintln!(" service stop Uninstall the system service"); + eprintln!(" service restart Restart the service with updated binary"); eprintln!(" service status Check if the service is running"); eprintln!(" help Show this help"); eprintln!(); diff --git a/src/system_dns.rs b/src/system_dns.rs index 1ca7ffd..40ff61a 100644 --- a/src/system_dns.rs +++ b/src/system_dns.rs @@ -416,6 +416,37 @@ pub fn uninstall_service() -> Result<(), String> { } } +/// Restart the service (kill process, launchd/systemd auto-restarts with new binary). +pub fn restart_service() -> Result<(), String> { + #[cfg(target_os = "macos")] + { + let output = std::process::Command::new("launchctl") + .args(["list", PLIST_LABEL]) + .output(); + match output { + Ok(o) if o.status.success() => { + // Service is loaded — kill the process, launchd restarts it + let _ = std::process::Command::new("pkill") + .args(["-f", "/usr/local/bin/numa"]) + .status(); + eprintln!(" Service restarting (launchd will respawn).\n"); + Ok(()) + } + _ => Err("Service is not installed. Run 'sudo numa service start' first.".to_string()), + } + } + #[cfg(target_os = "linux")] + { + run_systemctl(&["restart", "numa"])?; + eprintln!(" Service restarted.\n"); + Ok(()) + } + #[cfg(not(any(target_os = "macos", target_os = "linux")))] + { + Err("service restart not supported on this OS".to_string()) + } +} + /// Show the service status. pub fn service_status() -> Result<(), String> { #[cfg(target_os = "macos")]