如何在Ubuntu中作为守护进程启动Go程序?

编程入门 行业动态 更新时间:2024-10-28 16:24:44
本文介绍了如何在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程序?

本文发布于:2023-11-23 23:45:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623214.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   程序   如何在   Ubuntu

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!