From 8d0cbfd0ad5a5a05d3559e71d0b2ee1ba97a72a7 Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Fri, 15 Aug 2025 19:38:49 +0000 Subject: [PATCH] Implement cross-platform restart handling in WebUIServer. Add sendRestartSignal function to manage process signals based on the operating system, improving server restart functionality. --- src/webui/server.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/webui/server.go b/src/webui/server.go index 73f24979..d897a0ee 100644 --- a/src/webui/server.go +++ b/src/webui/server.go @@ -9,6 +9,7 @@ import ( "net" "net/http" "os" + "runtime" "strings" "sync" "syscall" @@ -595,15 +596,31 @@ func (w *WebUIServer) restartServer() { // Give some time for the response to be sent time.Sleep(1 * time.Second) - // Send SIGUSR1 signal to trigger a graceful restart - // This assumes the main process handles SIGUSR1 for restart + // Cross-platform restart handling proc, err := os.FindProcess(os.Getpid()) if err != nil { w.log.Errorf("Failed to find current process: %v", err) return } - if err := proc.Signal(syscall.SIGUSR1); err != nil { + // Try to send restart signal (platform-specific) + if err := sendRestartSignal(proc); err != nil { w.log.Errorf("Failed to send restart signal: %v", err) + w.log.Infof("Please restart Yggdrasil manually to apply configuration changes") + } +} + +// sendRestartSignal sends a restart signal to the process in a cross-platform way +func sendRestartSignal(proc *os.Process) error { + // Platform-specific signal handling + switch runtime.GOOS { + case "windows": + // Windows doesn't support SIGUSR1, so we'll use a different approach + // For now, we'll just log that manual restart is needed + // In the future, this could be enhanced with Windows-specific restart mechanisms + return fmt.Errorf("automatic restart not supported on Windows") + default: + // Unix-like systems support SIGUSR1 + return proc.Signal(syscall.SIGUSR1) } }