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

在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?

  • 写回答

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?