rails: rails restart doesn't work with puma3

Steps to reproduce

rails new foo
cd foo
rails server
rails restart

Expected behavior

Server should restart.

Actual behavior

Puma notices the change to tmp/restart.txt, stops the server, and attempts to restart the server with its own ideas of what ARGV should look like. Rails doesn’t like what it sees in ARGV, and spits out usage instructions. At that point, the server is down.

The problem also occurs with rails dev:cache.

System configuration

Rails version: Rails 5.0.0.beta3 (master)

Ruby version: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 21 (21 by maintainers)

Commits related to this issue

Most upvoted comments

I made some progress on this.

We need to provide a restart command to Puma which it will use while restarting the server. The command will be bin/rails s.

Even after this, there is an issue with existing pid file present in tmp/pids/server.pid file. I think it’s okey to remove that file manually from Rails side when doing rails restart or rails dev:cache. But would like to hear more opinions if I am missing something. (cc @rafaelfranca, @kaspth )

I think we will need to make some changes to Puma also to correctly accept the restart command from Rails. I got it working locally and will make a PR shortly to Puma.

$ rails s
=> Booting Puma
=> Rails 5.0.0.beta3 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
"conf options"
Puma starting in single mode...
* Version 3.2.0 (ruby 2.3.0-p0), codename: Spring Is A Heliocentric Viewpoint
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
* Restarting...
["bin/rails", "s", {:close_others=>true, 31=>31}]
"----------"
=> Booting Puma
=> Rails 5.0.0.beta3 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
"conf options"
Puma starting in single mode...
* Version 3.2.0 (ruby 2.3.0-p0), codename: Spring Is A Heliocentric Viewpoint
* Min threads: 5, max threads: 5
* Environment: development
* Inherited tcp://localhost:3000
Use Ctrl-C to stop

`def restart! @config.run_hooks :on_restart, self

  if Puma.jruby?
    close_binder_listeners

    require 'puma/jruby_restart'
    JRubyRestart.chdir_exec(@restart_dir, restart_args)
  elsif Puma.windows?
    close_binder_listeners

    argv = restart_args
    Dir.chdir(@restart_dir)
    Kernel.exec(*argv)
  else
    redirects = {:close_others => true}
    @binder.listeners.each_with_index do |(l, io), i|
    ENV["PUMA_INHERIT_#{i}"] = "#{io.to_i}:#{l}"
    redirects[io.to_i] = io.to_i
    end

    argv = restart_args
    Dir.chdir(@restart_dir)
    argv += [redirects] if RUBY_VERSION >= '1.9'

    #--------------
    pid = File.read('tmp/pids/server.pid')
    system("kill -9 #{pid} && sleep 10 && rails dev:cache && sleep 5 && rails tmp:clear && rails s")
    #--------------
  end
end`

I did this still get the same error as rubys 😦

From the messages, it appears that the port is being inherited.

More generally:

  • From a rails development perspective, the user starts the server in one terminal window and may return to that window occasionally to see status messages. It would be a desirable feature for the server to be restarted in that window.
  • Puma has support for features like phased restart that are not needed in a Rails development environment. Given that Evan seems motivated to support this scenario, I would suggest that if additional functionality is required to make this work, that such be added to puma, perhaps as a configuration option.

I’ve opened a separate issue to track the puma changes required: https://github.com/puma/puma/issues/907