Skip to content

Commit

Permalink
Merge pull request #1168 from skrashevich/fix-flags-daemon
Browse files Browse the repository at this point in the history
fix(app): Refactor daemon initialization and add syscall import
  • Loading branch information
AlexxIT committed Jun 18, 2024
2 parents ba34855 + db6745e commit f5aaee0
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,16 @@ func Init() {
os.Exit(0)
}

if daemon {
if daemon && os.Getppid() != 1 {
if runtime.GOOS == "windows" {
fmt.Println("Daemon not supported on Windows")
fmt.Println("Daemon mode is not supported on Windows")
os.Exit(1)
}

args := os.Args[1:]
for i, arg := range args {
if arg == "-daemon" || arg == "-d" {
args[i] = ""
}
}
// Re-run the program in background and exit
cmd := exec.Command(os.Args[0], args...)
cmd := exec.Command(os.Args[0], os.Args[1:]...)
if err := cmd.Start(); err != nil {
fmt.Println(err)
fmt.Println("Failed to start daemon:", err)
os.Exit(1)
}
fmt.Println("Running in daemon mode with PID:", cmd.Process.Pid)
Expand Down

0 comments on commit f5aaee0

Please sign in to comment.