1

I don't know if this is a stupid question or not, but how do I keep my puma server for my rails app running without having the puTTy window open to my ec2 instance? I'd like to have it fired up and then close the window and not have my PC on all the time.

2 Answers2

1

You can use screen

  1. Login to your server using putty
  2. Type screen
  3. Run your server
  4. Do ctrl-a and then press d
  5. Now your server is running in the background and you can disconnect from putty!

To resume the process(see the actual console)

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

Note that all screen processes will be killed on server restart

Tudor
  • 320
  • 1
  • 9
1

To keep puma server running in EC2, you've to daemonize it i.e. run it in background.

If you're using puma, you should have config/puma.rb file with daemonize true for non development environment. Your puma.rb file should look like

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 }

Now you can start it as bundle exec pumactl -F config/puma.rb start. You can similarly stop or restart the puma server.

Anurag Aryan
  • 611
  • 6
  • 16