How to create a daemon process in Golang? [duplicate]
Asked Answered
B

1

24

Has anyone here written a deamon process in Golang? Can you walk me through how to do that? Useful links are welcome.

Blooming answered 19/5, 2014 at 10:59 Comment(4)
Isn't is similar to https://mcmap.net/q/368726/-how-to-start-a-go-program-as-a-daemon-in-ubuntu/6309?Vachon
I checked that link. Solutions described in it are about demonizing an ordinary go program. I am looking for how to fork or setsuid.. etcBlooming
Then you will have to edit your question and add a lot of details about the specifics of said question.Vachon
I think it's close enough to a dupe to close. The linked question does contain an answer (in which there's a link to a bug) which describes the difficulties involved in forking/setsuid/etc. necessary to daemonize a go program.Primeval
A
23

Yes this has been done. See the go-daemon project. Be aware that there are certain problems when the daemonization happens after goroutines are launched. See issue 227 for details.

At this time I'd recommend to use the utilities your operating system offers you. See this related question for solutions.

Arrive answered 19/5, 2014 at 11:12 Comment(2)
For systems with systemd this is absolutely not necessary. For BSD, and systems with old upstart (c5, c6) you can use a small program like github.com/fiorix/go-daemon without changing your Go code.Hindustani
from immortal.run github.com/immortal/immortal/blob/master/fork.goStannite

© 2022 - 2024 — McMap. All rights reserved.