From 8d72e77d573a03cee3648f960ddd7c333f02b166 Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 24 Jul 2025 11:06:53 -0700 Subject: [PATCH] Service working? Former-commit-id: 7802248085f0c34e9a5c07c0815ab28c8fc4adcc --- main.go | 7 +++++++ service_unix.go | 4 ++++ service_windows.go | 17 ++++++++--------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index e6bbc4b..04597ab 100644 --- a/main.go +++ b/main.go @@ -87,6 +87,13 @@ func main() { os.Exit(1) } return + case "logs": + err := watchLogFile(false) + if err != nil { + fmt.Printf("Failed to watch log file: %v\n", err) + os.Exit(1) + } + return case "help", "--help", "-h": fmt.Println("Olm WireGuard VPN Client") fmt.Println("\nWindows Service Management:") diff --git a/service_unix.go b/service_unix.go index 014458f..c9f5fbf 100644 --- a/service_unix.go +++ b/service_unix.go @@ -44,3 +44,7 @@ func runService(name string, isDebug bool, args []string) { func setupWindowsEventLog() { // No-op on non-Windows platforms } + +func watchLogFile(end bool) error { + return fmt.Errorf("watching log file is only available on Windows") +} diff --git a/service_windows.go b/service_windows.go index 8d16eb5..de89ca9 100644 --- a/service_windows.go +++ b/service_windows.go @@ -373,12 +373,7 @@ func debugService(args []string) error { } } - // Get the log file path - logDir := filepath.Join(os.Getenv("PROGRAMDATA"), "Olm", "logs") - logFile := filepath.Join(logDir, "olm.log") - fmt.Printf("Starting service in debug mode...\n") - fmt.Printf("Log file: %s\n", logFile) // Start the service err := startService([]string{}) // Pass empty args since we already saved them @@ -390,10 +385,12 @@ func debugService(args []string) error { fmt.Printf("================================================================================\n") // Watch the log file - return watchLogFile(logFile) + return watchLogFile(true) } -func watchLogFile(logPath string) error { +func watchLogFile(end bool) error { + logDir := filepath.Join(os.Getenv("PROGRAMDATA"), "Olm", "logs") + logPath := filepath.Join(logDir, "olm.log") // Open the log file file, err := os.Open(logPath) if err != nil { @@ -422,8 +419,10 @@ func watchLogFile(logPath string) error { case <-sigCh: fmt.Printf("\n\nStopping log watch...\n") // stop the service if needed - if err := stopService(); err != nil { - fmt.Printf("Failed to stop service: %v\n", err) + if end { + if err := stopService(); err != nil { + fmt.Printf("Failed to stop service: %v\n", err) + } } fmt.Printf("Log watch stopped.\n") return nil