So I've been tinkering with go for the past two weeks and I've been trying to figure out what the easiest way to serve my http server application as a daemon. The search results were pretty much over my head, so I took go out of the picture and came across this guide
Could I apply this guide to a go server? I haven't had time to try it yet, but I guess the best place to ask would be here.
评论:
kardianos:
SaltTM:If you are struggling with a simple default, you could use the package
github.com/kardianos/service
which will let you run it as a service on windows/osx/systemd/sysv with the same code base.
Frakturfreund:wish that was a bit more documented, but I assume using runner would do what i wanted
the_jester:Yes, you can. But parts of it seems to be a little outdated; both Ubuntu and Debian have switched to systemd (like Arch Linux).
pschlump:Broadly speaking, yes. Your software may want to have some "good habits", in terms of pidfile handling, and catching signals gracefully, but even if it does not, all those listed process managers are agnostic. They don't care if your program is in C, Python, or Go.
In 1.5 of Go I had a bunch of problems with go-routines not working happily when combined with begin a service and a Linux chroot. My solution was a C wrapper that started and managed the Go code. I am not certain if the problems were fixed in 1.6+ of Go. This related to changing of ownership of sub-processes and not changing all the threads in the Go Program - thereby leaving some threads running as root. This would not apply to Windows - if on windows use the github.com/kardianos/service package - it works. If on linux you might consider: github.com/pschlump/daemon-it
