Has anyone here written a deamon process in Golang? Can you walk me through how to do that? Useful links are welcome.
Asked
Active
Viewed 5.6k times
24
-
Isn't is similar to http://stackoverflow.com/q/10067295/6309? – VonC May 19 '14 at 11:02
-
I checked that link. Solutions described in it are about demonizing an ordinary go program. I am looking for how to fork or setsuid.. etc – Kasinath Kottukkal May 19 '14 at 11:04
-
Then you will have to edit your question and add *a lot* of details about the specifics of said question. – VonC May 19 '14 at 11:05
-
1I 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. – Paul Hankin May 19 '14 at 11:13
1 Answers
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.
-
3For systems with systemd this is absolutely not necessary. For BSD, and systems with old upstart (c5, c6) you can use a small program like https://github.com/fiorix/go-daemon without changing your Go code. – fiorix Apr 15 '16 at 14:12
-
from https://immortal.run https://github.com/immortal/immortal/blob/master/fork.go – nbari Jan 04 '18 at 20:11