ku1ik / racksh

Console for Rack based ruby web apps

Home Page:https://ku1ik.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reload app from racksh

akahn opened this issue · comments

Rails' script/console supports a reload! command, which reloads the application so that the user can interact with the app's most up-to-date code without exiting and restarting the console. I request that racksh support such a feature.

Thank you,
Alex

I don't know how Rails implemented this but I know that either in Merb and some other frameworks like Sinatra this "reloading" feature wasn't always working as expected (it was removed from Sinatra because of that).

In such dynamic language like ruby it isn't possible to reload completely. It's working in Rails but it would need to be implemented also in every framework to be reliable.

But if you have an idea how to approach this feel free to comment.

I think you can re-create a new session (Rack:Shell:Session)

# Just for example if its possible
if command == "reload!"
  $rack = Rack::Shell::Session.new(rack_app)
  puts "racksh is reloaded!"
end

Thanks,

Bryan

Hi sickill,

I believe reloading was removed from sinatra partly because it didn't work well and partly because shotgun (http://github.com/rtomayko/shotgun) was doing it better.

As for how Rails is doing it, here's the method in their API documentation: http://api.rubyonrails.org/files/vendor/rails/railties/lib/console_app_rb.html#M000003 The reload! method calls cleanup_application and reload_application methods (http://api.rubyonrails.org/classes/ActionController/Dispatcher.html#M000674), et cetera, et cetera.

So, no, I don't have an idea how to approach this. ;)

Alex

Hello!

first thanks for racksh, it's a very useful tool!

On reloading: I would even take something that would just restart the whole thing (literally), it would already be useful.

Is there already some trick to achieve that ?

-- Thibaut

Yes, I think this would be the best and safest approach. I'm thinking about forking the process during startup, just before config.ru is loaded. Then if user want's to reload it I kill current process and just start another one (which loads config.ru) exactly like for the first time.

Hi guys,

I've just released racksh 0.9.6 with reloading support :) I've decided to use forking as the most safe solution.

Anyway you can now reload whole app with reload! command. Check it out and tell me if it works ok for your rack apps.

Marcin

Works for me!

Thanks Marcin.

It has been confirmed to work so I'm closing this issue.