如何在 Ubuntu 中将 Go 程序作为守护程序启动? [英] How to start a Go program as a daemon in Ubuntu?

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

问题描述

在 Ubuntu 中将 Go 程序作为守护程序启动的正确方法是什么?然后我将使用 Monit 对其进行监控.我应该做类似的事情吗:

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 &

我应该考虑哪些特定于 Go 的事情?

Are there things specific to Go that I should take into account ?

推荐答案

您应该为您的程序构建一个可执行文件 (go build),然后为 upstart 它将作为守护程序运行您的程序,或者使用诸如 守护.我更喜欢后一种解决方案,因为它不依赖于依赖系统的暴发户.使用 daemonize,您可以像

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

这将为您提供一个运行良好的 unix 守护进程,其中所有必要的守护进程都由 daemonize 完成.

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆