在Ubuntu中启动Go程序作为守护程序的正确方法是什么?然后我会用Monit监控它。我应该做些什么:
go run myapp.go&是否有特定于Go的事物,我应该考虑?
您应该为您的程序构建一个可执行文件( go build ),然后为 它会为你运行你的程序作为守护进程,或者使用外部工具,比如守护进程。我更喜欢后一种解决方案,因为它不依赖于依赖系统的新贵。使用守护进程,您可以像开始您的应用程序一样 daemonize -p /var/run/myapp.pid -l / var / lock / subsys / myapp -u nobody /path/to/myapp.exe这会给你一个很好的解释,使用守护进程完成所有必需的守护进程,从而执行unix守护进程。
What is the proper way to start a Go program as a daemon in Ubuntu ? I will then monitor it with Monit. Should I just do something like:
go run myapp.go &Are there things specific to Go that I should take into account ?
解决方案You should build an executable for your program (go build) and then either write a script for upstart and it will run your program as a daemon for you, or use an external tool like daemonize. I prefer the latter solution, because it does not depend on a system-dependent upstart. With daemonize you can start your application like
daemonize -p /var/run/myapp.pid -l /var/lock/subsys/myapp -u nobody /path/to/myapp.exeThis will give you a well-behaving unix daemon process with all necessary daemon preparations done by daemonize.
更多推荐
如何在Ubuntu中作为守护进程启动Go程序?
发布评论