ruby-on-rails – 有没有办法使用capistrano(或类似的)远程与rails控制台进行交互

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 有没有办法使用capistrano(或类似的)远程与rails控制台进行交互前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我很喜欢capistrano如何简化了我的部署工作流程,但是经常会有一次推送的更改会遇到我需要登录服务器以通过控制台进行故障排除的问题.

有没有办法使用capistrano或其他远程管理工具与本地终端上的服务器上的rails控制台进行交互?

**更新:

帽壳看起来很有希望,但是当您尝试启动控制台时它会挂起:

  1. cap> cd /path/to/application/current
  2. cap> pwd
  3. ** [out :: application.com] /path/to/application/current
  4. cap> rails c production
  5. ** [out :: application.com] Loading production environment (Rails 3.0.0)
  6. ** [out :: application.com] Switch to inspect mode.

如果你知道一个解决办法,那将是巨大的

解决方法

我发现基于 https://github.com/codesnik/rails-recipes/blob/master/lib/rails-recipes/console.rb的相当不错的解决方
  1. desc "Remote console"
  2. task :console,:roles => :app do
  3. env = stage || "production"
  4. server = find_servers(:roles => [:app]).first
  5. run_with_tty server,%W( ./script/rails console #{env} )
  6. end
  7.  
  8. desc "Remote dbconsole"
  9. task :dbconsole,%W( ./script/rails dbconsole #{env} )
  10. end
  11.  
  12. def run_with_tty(server,cmd)
  13. # looks like total pizdets
  14. command = []
  15. command += %W( ssh -t #{gateway} -l #{self[:gateway_user] || self[:user]} ) if self[:gateway]
  16. command += %W( ssh -t )
  17. command += %W( -p #{server.port}) if server.port
  18. command += %W( -l #{user} #{server.host} )
  19. command += %W( cd #{current_path} )
  20. # have to escape this once if running via double ssh
  21. command += [self[:gateway] ? '\&\&' : '&&']
  22. command += Array(cmd)
  23. system *command
  24. end

猜你在找的Ruby相关文章