gpt4 book ai didi

go - 在 CentOS 7 上将 Go 作为守护进程网络服务器运行

转载 作者:数据小太阳 更新时间:2023-10-29 03:37:39 25 4
gpt4 key购买 nike

我正在尝试从 PHP 迁移到 Go,并计划完全放弃 nginx。但是我不知道如何在后台将 go http 网络服务器作为守护进程运行,我也不知道如何在我重新启动时自动启动网络服务器,或者如何终止进程。

对于nginx,我所做的就是

$ systemctl start nginx.service
$ systemctl restart nginx.service
$ systemctl stop nginx.service
$ systemctl enable nginx.service
$ systemctl disable nginx.service

这很方便,但似乎我不能用 Go http 服务器来做到这一点。我必须像任何其他 Go 程序一样编译和运行它。这些问题有哪些解决方案?

最佳答案

这与其说是围棋问题,不如说是系统管理问题。有多种方法可以向 systemd 添加命令(如 this blog post )。

就个人而言,我更喜欢将我的应用程序与我的服务分开,所以我倾向于使用 supervisord对于我的经常启动、停止或重新启动的程序。 supervisord 的文档非常简单,但基本上您可以创建一个配置文件来描述您要运行的服务,用于运行它的命令(例如 /path/to/go/binary -flag) 您希望如何处理启动、停止、故障恢复、日志记录等...

关于go - 在 CentOS 7 上将 Go 作为守护进程网络服务器运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31149940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com