diff --git a/main.go b/main.go index fb57d8c..4567c9f 100644 --- a/main.go +++ b/main.go @@ -130,7 +130,7 @@ func becomeDaemon() { PidFileName: pidPath, PidFilePerm: 0644, WorkDir: cwd, - Umask: 027, + Umask: 002, } dmn, err := ctx.Reborn() @@ -139,22 +139,26 @@ func becomeDaemon() { os.Exit(1) } if dmn != nil { - ctx.Release() // parent process no longer needed os.Exit(0) } - defer ctx.Release() // -- WE ARE NOW THE DAEMON -- // write pid if pidPath != "" { - pidFile, _ := os.OpenFile(pidPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + pidFile, err := os.OpenFile(pidPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(0644)) + if err != nil { + log.Errorf("failed to create pidfile: %v", err) + } defer pidFile.Close() pidBytes := []byte(strconv.Itoa(os.Getpid())) - pidFile.Write(pidBytes) + _, err = pidFile.Write(pidBytes) + if err != nil { + log.Errorf("failed to write pidfile: %v", err) + } } } @@ -175,7 +179,6 @@ func nodeMain() { setupLogging(config.Log) // only after logging setup, we may became daemon - println(pidPath) if daemonize { becomeDaemon() }