好的,所以我想在Rails中创建一个动作来重启自己.我做了一点搜索,发现:
http://snippets.dzone.com/posts/show/5002
这表示2个命令,一个停止,另一个重启.以下杀戮:
ps -a|grep "/usr/local/bin/ruby script/server"|grep -v "grep /usr"|cut -d " " -f1|xargs -n 1 kill -KILL $1
-HUP信号没有为我重新启动,所以我试图破坏上面的命令(调整使命令工作正常,我在Ubuntu下启动服务器):
ps -eaf|grep "ruby script/server"|grep -v grep|cut -d " " -f3|xargs -n 1 kill -KILL $1;script/server
这在我的环境中工作正常,所以我尝试设置一个动作来执行它:
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
该操作可以很好地杀死服务器,但实际上并没有启动服务器备份:
=> 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
当Mongrel似乎刚刚退出时,我不太明白为什么地址已经被使用了.
我发现了这个问题:
如何在不停止和启动Mongrel的情况下重启Mongrel下的Rails
但是信号不会导致我的环境重启,他们最终会杀死进程.
任何人对什么可行有任何想法?关于我的环境的一些注意事项:我从新版本的RubyGems和Mongrel安装了Rails.我使用脚本/服务器启动服务器,当然使用Mongrel.我在Ubuntu Hardy Heron上.