试图在没有 putty window 的情况下保持我的 Puma 服务器 运行 打开

trying to keep my puma server running without the putty window open

我不知道这是否是一个愚蠢的问题,但是如何在不打开 PuTTy window 的情况下为我的 rails 应用程序 运行 保留我的 Puma 服务器到我的 ec2 实例?我想让它启动,然后关闭 window,而不是让我的电脑一直开着。

您可以使用screen

  1. 使用 putty 登录您的服务器
  2. 类型screen
  3. 运行 你的服务器
  4. 按 ctrl-a 然后按 d
  5. 现在您的服务器 运行 在后台,您可以断开与 putty 的连接!

恢复进程(查看实际控制台)

  1. screen -ls
  2. screen -r <screen_name>

请注意,所有屏幕进程都将在服务器重启时终止

要在 EC2 中保留 puma 服务器 运行ning,您必须对其进行守护进程,即 运行 它在后台。

如果您使用的是 puma,您应该有 config/puma.rb 非开发环境的 daemonize 文件。您的 puma.rb 文件应该类似于

railsenv = ENV.fetch("RAILS_ENV") { "development" }
environment railsenv

if railsenv != "development"

  application_path = '/home/ubuntu/hybrid'
  daemonize true
  directory application_path

  pidfile "#{application_path}/tmp/pids/puma-#{railsenv}.pid"
  state_path "#{application_path}/tmp/pids/puma-#{railsenv}.state"

  stdout_redirect "#{application_path}/log/puma-#{railsenv}.stdout.log", "#{application_path}/log/puma-#{railsenv}.stderr.log"
  workers ENV.fetch("WEB_CONCURRENCY") { 2 }

end

threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count

port        ENV.fetch("PORT") { 3000 }

现在您可以 bundle exec pumactl -F config/puma.rb start 启动它了。您可以类似地 stoprestart puma 服务器。