在 Linux 服务器上保持 Go 脚本在 SSH 连接关闭后继续运行。

huangapple go评论73阅读模式
英文:

Keep Go script running on Linux server after ssh connection is closed

问题

我有一个Go脚本,它创建一个HTTP请求并响应任何传入的请求。我希望这个脚本在Linux服务器上运行。然而,我不能永远保持ssh连接处于活动状态,当连接断开时,脚本也会停止,这是预期的。我知道NodeJS有一个名为"forever"的工具可以解决这个问题。我想知道是否有类似的工具适用于Golang,因为我找不到相关信息。对于如何解决这个问题的其他建议也非常欢迎。

英文:

I have a Go script that creates an HTTP request and responds to any incoming requests. I want this script to run on a Linux server. However, I can't keep the ssh connection active forever, and when it disconnects the script also stops, as expected. I know that you have 'forever' for NodeJS that fixes this issue. I was wondering if something similar also exists for Golang, as I was not able to find anything. Any other tips on how to fix this are also very welcome.

答案1

得分: 1

这里主要有三个选项,一个是使用nohup命令,另一个是使用screen命令,最后一个是screen的升级版本byobu。在阅读了这三个命令之后,我实际上更喜欢使用byobu命令,因为byobu命令更强大,是screen的升级版本,并且界面更友好。

英文:

There are mainly three options here, one is to use the nohup command, the other is to use the screen command, and the last is the upgraded version of byobu of screen. After reading these three commands, I actually prefer to use the byobu command, because the byobu command is more powerful, an upgraded version of screen, and the interface is more friendly.

huangapple
  • 本文由 发表于 2021年12月27日 04:48:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/70489763.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定