有没有办法使用capistrano(或类似)远程交互rails控制台 [英] Is there a way to use capistrano (or similar) to remotely interact with rails console

查看:157
本文介绍了有没有办法使用capistrano(或类似)远程交互rails控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



**更新: / p>

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

  cap> cd / path / to / application / current 
cap> pwd
** [out :: application.com] / path / to / application / current
cap> rails c production
** [out :: application.com]加载生产环境(Rails 3.0.0)
** [out :: application.com]切换到检查模式。

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

解决方案

我发现相当不错的解决方案基于 https://github.com/codesnik/rails-recipes/blob/master/lib/rails-recipes/console.rb

  desc远程控制台
task:console,:roles => :app do
env = stage || production
server = find_servers(:roles => [:app])。first
run_with_tty服务器,%W(./script/rails console#{env})
end

desc远程dbconsole
任务:dbconsole,:roles => :app do
env = stage || production
server = find_servers(:roles => [:app])。first
run_with_tty服务器,%W(./script/rails dbconsole#{env})
end

def run_with_tty(server,cmd)
#看起来像总pizdets
command = []
命令+ =%W(ssh -t#{gateway} -l #{self [:gateway_user] || self [:user]})if self [:gateway]
命令+ =%W(ssh -t)
命令+ =%W server.port})如果server.port
命令+ =%W(-l#{user}#{server.host})
命令+ =%W(cd#{current_path})
#如果通过double ssh
命令+ = [self [:gateway]? '\& \&':'&&']
command + = Array(cmd)
system * command
end


I'm loving how capistrano has simplified my deployment workflow, but often times a pushed change will run into issues that I need to log into the server to troubleshoot via the console.

Is there a way to use capistrano or another remote administration tool to interact with the rails console on a server from your local terminal?

**Update:

cap shell seems promising, but it hangs when you try to start the console:

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.

if you know a workaround for this, that'd be great

解决方案

I found pretty nice solution based on 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

这篇关于有没有办法使用capistrano(或类似)远程交互rails控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆