douzhanhui5662
2015-06-30 23:00
浏览 85
已采纳

在CentOS 7上将Go作为守护程序Web服务器运行

I am trying to migrate from PHP to Go and planning to drop nginx alltogether. But I don't know how to run the go http webserver as a deamon in the background and I also don't know how to automatically start the webserver if I make a reboot, or how to kill the process.

With nginx all I do is

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

This is very convenient, but it seems like I can't do this with Go http server. I have to compile and run it as any other Go program. What solutions do exist for these concerns?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试从PHP迁移到Go,并计划一起删除nginx。 但是我不知道如何在后台将go http Web服务器作为守护进程运行,并且我也不知道如何在重新启动后自动启动Web服务器或如何终止该进程。 \ n

使用nginx我要做的就是

  $ systemctl start nginx.service 
 $ systemctl restart nginx.service 
 $ systemctl stop nginx.service 
  $ systemctl启用nginx.service 
 $ systemctl禁用nginx.service 
   
 
 

这非常方便,但似乎我无法通过Go http服务器执行此操作 。 我必须像其他任何Go程序一样编译并运行它。 有什么解决方案可以解决这些问题?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpgvdfg321041670 2015-06-30 23:47
    已采纳

    This is less of a Go question and more of a Systems Administration question. There are ways to add a command to systemd (like in this blog post).

    Personally, I prefer to keep my applications separate from my services, so I tend to use supervisord for my programs that tend to be started, stopped, or restarted frequently. The documentation for supervisord is pretty straightforward, but essentially you can create a config file to describe the services you want to run, the command used to run it (such as /path/to/go/binary -flag) how you want to handle starting, stopping, failure recovery, logging, etc....

    点赞 评论

相关推荐 更多相似问题