How to restart Rails from Rails?

Ok, so I would like to create an action in Rails to restart. I searched a bit and found:

http://snippets.dzone.com/posts/show/5002

Which offers two commands, one for stopping and one for restarting. The following killings:

ps -a|grep "/usr/local/bin/ruby script/server"|grep -v "grep /usr"|cut -d " " -f1|xargs -n 1 kill -KILL $1 

The -HUP signal does not restart for me, so I tried to hide the command above (adjusted so that the command worked fine with the way I started the server under Ubuntu):

 ps -eaf|grep "ruby script/server"|grep -v grep|cut -d " " -f3|xargs -n 1 kill -KILL $1;script/server 

This works fine in my environment, so I tried to configure the action to execute it:

 def restart fork { exec "ps -eaf|grep \"ruby script/server\"|grep -v grep|cut -d \" \" -f3|xargs -n 1 kill -KILL $1;script/server" } redirect_to "/server_maintenance" end 

The action perfectly destroys the server, but does not actually start the server backup:

 => Booting Mongrel => Rails 2.3.2 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Exiting /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/tcphack.rb:12:in `initialize_without_backlog': Address already in use - bind(2) (Errno::EADDRINUSE) from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/tcphack.rb:12:in `initialize' from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:93:in `new' from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:93:in `initialize' from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb:10:in `new' from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb:10:in `run' from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from script/server:3 

I don’t quite understand why the address is already in use when Mongrel seems to have just left.

I found this question:

How to restart Rails under Mongrel without stopping or starting Mongrel .

but the signals do not restart in my environment, they just kill the process.

Anyone have any ideas on what might work? For some notes in my environment: I installed Rails from the new version of RubyGems and Mongrel. I use script / server to start the server, which of course uses Mongrel. I'm on Ubuntu Hardy Heron.

+6
ruby ruby-on-rails mongrel
source share
3 answers

Ok, I found a fix ... I changed the way rails start:

 mongrel_rails start -d 

and now the following action will be performed:

 def restart fork { exec "mongrel_rails restart" } redirect_to "/server_maintenance" end 

As a warning, redirect_to will cause a loss of failure since the server will shut down ... however, rebooting after a pause will indicate that the restart was successful. This could be fixed by changing the restart that needs to be done using AJAX, followed by a reboot of javascript ... but I will leave this as an exercise for the reader.

+3
source share

If you don't mind switching to mod_rails, you can restart your server by creating $ RAILS_ROOT / tmp / restart.txt, which means that you no longer need the Rails instance.

Your PS team looks (with a cursor look) as if it will kill all the rail processes in your box. This is great if you are the only Rails application on the machine, but if there are multiple launches as the same user or you use root, you will kill them. Bad shape!

This indicates mongrel. There, as you want to try.

+4
source share

In our consulting with the launch of our sites on Rails, we used two methods for managing mongrel processes.

Firstly, this is a special stone that we wrote, called mongrel_runit . This sets mongrels as services in runit .

Secondly, we used god to track mongrel processes. This will work with mongrel_runit or with "normal" mongrel configurations.

0
source share

All Articles