use go-daemon library

This commit is contained in:
Aliberk Sandıkçı 2023-07-29 13:11:02 +03:00
parent 8fd2cd77cf
commit 56fc88c9fc
Signed by: asandikci
GPG key ID: 25C67A03B5666BC1

View file

@ -1,33 +1,34 @@
package main
import (
// "log"
"log"
"time"
// "github.com/sevlyar/go-daemon"
"github.com/sevlyar/go-daemon"
)
func main() {
// cntxt := &daemon.Context{
// PidFileName: "godaemon1.pid",
// PidFilePerm: 0644,
// LogFileName: "godaemon1.log",
// LogFilePerm: 0640,
// WorkDir: "./",
// Umask: 027,
// Args: []string{"[go-daemon godaemon1]"},
// }
cntxt := &daemon.Context{
PidFileName: "godaemon1.pid",
PidFilePerm: 0644,
LogFileName: "godaemon1.log",
LogFilePerm: 0640,
WorkDir: "./",
Umask: 027,
Args: []string{"[go-daemon godaemon1]"},
}
// d, err := cntxt.Reborn()
// if err != nil {
// log.Fatal("Unable to run: ", err)
// }
// if d != nil {
// return
// }
// defer cntxt.Release()
//
// log.Print("- - - - - - - - - - - - - - -")
// log.Print("daemon started")
d, err := cntxt.Reborn()
if err != nil {
log.Fatal("Unable to run: ", err)
}
if d != nil {
return
}
defer cntxt.Release()
log.Print("- - - - - - - - - - - - - - -")
log.Print("daemon started")
for true {
Info()