本文介绍了如何在Ubuntu中作为守护进程启动Go程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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.exe

This will give you a well-behaving unix daemon process with all necessary daemon preparations done by daemonize.

这篇关于如何在Ubuntu中作为守护进程启动Go程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 07:31