Tell Webrick to load everything / restart on next request (something like restart.txt)

StackOverflow https://stackoverflow.com/questions/22465596

  •  16-06-2023
  •  | 
  •  

Question

Is there a way to tell Webrick to reload everything on the next request? Something like tmp/restart.txt for passenger?

I love guard and would like it to restart my development server whenever a critical file changes. I accomplished to stop the server using guard-shell:

guard :shell do
  watch %r{\.ruby-version|Gemfile|Gemfile\.lock|config/(application|environment)\.rb|config/environments/.*\.rb|config/initializers/.*\.rb} do |m|
    `lsof -i tcp:3000 | awk 'NR!=1 {print $2}' | xargs kill -9`
    n "#{m[0]} saved, restart of development server needed", 'Webrick restart'
  end
end

But it would be great to have it restarted automatically.

I also tried other options like pow in combination with powder which automatically reloads pow successfully, and also phusion passenger with a guard-shell script that touches tmp/restart.txt, which also works.

BUT: I want to use pry from within the server output, so I can simply add a binding.pry somewhere in my code and debug it in the console, and whether pow nor passenger seem to allow this: while pow disregards any binding.pry and does not halt, passenger seems to halt, but the interaction with pry is very strange, not every keystroke seems to reach it, etc.

So webrick is still my favorite and works very well... if I could just make it restart somehow automatically...

Was it helpful?

Solution

I found another way to do this. Just create a bin/server executable file in your Rails project with the following content:

#!/bin/bash

# This starts webrick using rerun which automatically restarts it after critical config files are changed
rerun --pattern '{Gemfile.lock,config/environment.rb,config/environments/development.rb,config/initializers/*.rb,lib/**/*.rb}' --no-growl --signal INT --background --clear -- rails s

Then install the rerun gem: gem install rerun.

Now simply start webrick by typing server (instead of rails server) and rerun will take care of restarting the server whenever an important file is changed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top