有没有办法使用capistrano(或类似)远程与rails控制台交互

Nei*_*kar 10 console capistrano ruby-on-rails

我很喜欢capistrano如何简化我的部署工作流程,但是经常推送的更改会遇到我需要登录到服务器以通过控制台进行故障排除的问题.

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

**更新:

cap shell似乎很有前途,但是当你尝试启动控制台时它会挂起:

cap> cd /path/to/application/current
cap> pwd
 ** [out :: application.com] /path/to/application/current
cap> rails c production
 ** [out :: application.com] Loading production environment (Rails 3.0.0)
 ** [out :: application.com] Switch to inspect mode.
Run Code Online (Sandbox Code Playgroud)

如果你知道一个解决方法,那就太好了

小智 12

我找到了基于https://github.com/codesnik/rails-recipes/blob/master/lib/rails-recipes/console.rb的非常好的解决方案

desc "Remote console" 
task :console, :roles => :app do
  env = stage || "production"
  server = find_servers(:roles => [:app]).first
  run_with_tty server, %W( ./script/rails console #{env} )
end

desc "Remote dbconsole" 
task :dbconsole, :roles => :app do
  env = stage || "production"
  server = find_servers(:roles => [:app]).first
  run_with_tty server, %W( ./script/rails dbconsole #{env} )
end

def run_with_tty(server, cmd)
  # looks like total pizdets
  command = []
  command += %W( ssh -t #{gateway} -l #{self[:gateway_user] || self[:user]} ) if     self[:gateway]
  command += %W( ssh -t )
  command += %W( -p #{server.port}) if server.port
  command += %W( -l #{user} #{server.host} )
  command += %W( cd #{current_path} )
  # have to escape this once if running via double ssh
  command += [self[:gateway] ? '\&\&' : '&&']
  command += Array(cmd)
  system *command
end
Run Code Online (Sandbox Code Playgroud)