takama / daemon

A daemon package for use with Go (golang) services
MIT License
1.96k stars 291 forks source link

Invalid daemon kind specified #104

Open ImanMousavi opened 2 years ago

ImanMousavi commented 2 years ago

* func main() { srv, err := daemon.New(name, description, daemon.SystemDaemon) if err != nil { // <-- Invalid daemon kind specified errlog.Println("Error: ****", err) os.Exit(1) }

service := &Service{srv}
status, err := service.Manage()
if err != nil {
    log.Fatal(status, "\nError: ", err)
}
fmt.Println(status)

rand.Seed(time.Now().UnixNano())

}

NateThornton commented 2 years ago

If you're running on MacOSX; the simple example will not work as daemon.SystemDaemon is not supported. Try changing it to a different kind like GlobalDaemon

https://github.com/takama/daemon/blob/496d69192531c6cb1004380a0be0fcf2031b06f4/daemon.go#L211-L232

ImanMousavi commented 2 years ago

Tank you

prologic commented 2 years ago

Just trying out your package. The "problem" on macOS is that neither UserAgent nor GlobalDaemon really "daemonize" the process. Is this a bug?

doothez commented 1 year ago

Just trying out your package. The "problem" on macOS is that neither UserAgent nor GlobalDaemon really "daemonize" the process. Is this a bug?

Below code work for me for both MacOS and Linux.

func main() {
    var kind daemon.Kind
    switch runtime.GOOS {
    case "darwin":
        kind = daemon.GlobalDaemon
    default:
        kind = daemon.SystemDaemon
    }
    srv, err := daemon.New(name, description, kind, dependencies...)
    if err != nil {
        errlog.Println("Error: ", err)
        os.Exit(1)
    }
    service := &Service{srv}
    status, err := service.Manage()
    if err != nil {
        errlog.Println(status, "\nError: ", err)
        os.Exit(1)
    }
    fmt.Println(status)
}