Service working?

This commit is contained in:
Owen
2025-07-24 11:06:53 -07:00
parent e4c030516b
commit 7802248085
3 changed files with 19 additions and 9 deletions

View File

@@ -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:")

View File

@@ -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")
}

View File

@@ -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