Skip to content

Commit f5aaee0

Browse files
authored
Merge pull request #1168 from skrashevich/fix-flags-daemon
fix(app): Refactor daemon initialization and add syscall import
2 parents ba34855 + db6745e commit f5aaee0

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

internal/app/app.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,16 @@ func Init() {
4545
os.Exit(0)
4646
}
4747

48-
if daemon {
48+
if daemon && os.Getppid() != 1 {
4949
if runtime.GOOS == "windows" {
50-
fmt.Println("Daemon not supported on Windows")
50+
fmt.Println("Daemon mode is not supported on Windows")
5151
os.Exit(1)
5252
}
5353

54-
args := os.Args[1:]
55-
for i, arg := range args {
56-
if arg == "-daemon" || arg == "-d" {
57-
args[i] = ""
58-
}
59-
}
6054
// Re-run the program in background and exit
61-
cmd := exec.Command(os.Args[0], args...)
55+
cmd := exec.Command(os.Args[0], os.Args[1:]...)
6256
if err := cmd.Start(); err != nil {
63-
fmt.Println(err)
57+
fmt.Println("Failed to start daemon:", err)
6458
os.Exit(1)
6559
}
6660
fmt.Println("Running in daemon mode with PID:", cmd.Process.Pid)

0 commit comments

Comments
 (0)