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.
ruby ruby-on-rails mongrel
Mike stone
source share