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 <noreply@anthropic.com>
This commit is contained in:
@@ -14,8 +14,8 @@ use numa::override_store::OverrideStore;
|
|||||||
use numa::query_log::QueryLog;
|
use numa::query_log::QueryLog;
|
||||||
use numa::stats::ServerStats;
|
use numa::stats::ServerStats;
|
||||||
use numa::system_dns::{
|
use numa::system_dns::{
|
||||||
discover_system_dns, install_service, install_system_dns, service_status, uninstall_service,
|
discover_system_dns, install_service, install_system_dns, restart_service, service_status,
|
||||||
uninstall_system_dns,
|
uninstall_service, uninstall_system_dns,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -41,9 +41,10 @@ async fn main() -> numa::Result<()> {
|
|||||||
return match sub.as_str() {
|
return match sub.as_str() {
|
||||||
"start" => install_service().map_err(|e| e.into()),
|
"start" => install_service().map_err(|e| e.into()),
|
||||||
"stop" => uninstall_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()),
|
"status" => service_status().map_err(|e| e.into()),
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!("Usage: numa service <start|stop|status>");
|
eprintln!("Usage: numa service <start|stop|restart|status>");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -57,6 +58,7 @@ async fn main() -> numa::Result<()> {
|
|||||||
eprintln!(" uninstall Restore original system DNS settings");
|
eprintln!(" uninstall Restore original system DNS settings");
|
||||||
eprintln!(" service start Install as system service (auto-start on boot)");
|
eprintln!(" service start Install as system service (auto-start on boot)");
|
||||||
eprintln!(" service stop Uninstall the system service");
|
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!(" service status Check if the service is running");
|
||||||
eprintln!(" help Show this help");
|
eprintln!(" help Show this help");
|
||||||
eprintln!();
|
eprintln!();
|
||||||
|
|||||||
@@ -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.
|
/// Show the service status.
|
||||||
pub fn service_status() -> Result<(), String> {
|
pub fn service_status() -> Result<(), String> {
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
|
|||||||
Reference in New Issue
Block a user