在ssh终止后如何使服务器在EC2上运行

我有一个EC2实例,我在其上安装了rails服务器。 当我这样做时,服务器运行正常

rails server 

但在关闭ssh连接后,服务器也会停止。 即使在关闭ssh连接后,如何使服务器保持运行。

 screen rails s 

做了伎俩

之后CTRL + A + D和我离开,服务器运行正常

试试这个。 我们必须启动rails server作为守护进程。

 rails s -d & 

运行在服务器上意味着通过nginx或apache或者这个开发服务器并不意味着作为服务器用户运行这需要更多信息https://www.digitalocean.com/community/articles/how-to-install-rails-and- nginx-with-passenger-on-ubuntu如果想要提前解决使用橡胶https://github.com/rubber/rubber

我需要我的一切都不运行,只需在后台运行。 安装屏幕,使子终端不受您的ssh连接影响。 sudo apt-get install screen打开screen然后启动rails rails server &

按’Crtl + A’然后’D’退出并输入screen -r以返回到屏幕终端。

我会建议使用apache或其他东西而不是常规的rails服务器,但你可以在最后添加&并随意离开

 rails server & 

这些步骤对我有用。 我的操作系统是描述: Ubuntu 16.04.4 LTS

  • sudo apt-get install screen
  • screen rails s
  • 从终端 CTRL + A + D 分离现有进程并让它运行

这是使用RVM和Systemd的生产certificate版本。 如果服务器因任何原因被终止,将使服务器保持活动状态。

 [Unit] Description=Puma Control After=network.target [Service] Type=forking User=user WorkingDirectory=/var/www/your_project_name PIDFile=/var/www/your_project_name/shared/tmp/pids/puma.pid ExecStart=/home/user/.rvm/bin/rvm default do bundle exec puma -C /var/www/your_project_name/shared/puma.rb --daemon ExecStop=/home/user/.rvm/bin/rvm default do bundle exec pumactl -S /var/www/your_project_name/shared/tmp/pids/puma.state -F /var/www/your_project_name/shared/puma.rb stop Restart=always # RestartSec=10 [Install] WantedBy=default.target