Ruby on rails 有没有一种方法可以使用capistrano(或类似工具)与rails控制台进行远程交互

Ruby on rails 有没有一种方法可以使用capistrano(或类似工具)与rails控制台进行远程交互,ruby-on-rails,console,capistrano,Ruby On Rails,Console,Capistrano,我很喜欢capistrano简化了我的部署工作流程,但通常情况下,推动的更改会遇到问题,我需要登录到服务器,通过控制台进行故障排除 有没有办法使用capistrano或其他远程管理工具从本地终端与服务器上的rails控制台进行交互 **更新: cap外壳看起来很有希望,但当您尝试启动控制台时,它会挂起: cap> cd /path/to/application/current cap> pwd ** [out :: application.com] /path/to/applica

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

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

**更新:

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

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.

如果您知道这方面的解决方法,那将是非常好的

不一定是最好的选择,但我在我们的项目中针对这个问题将以下内容结合在一起:

task :remote_cmd do
  cmd = fetch(:cmd)

  puts `#{current_path}/script/console << EOF\r\n#{cmd}\r\n EOF`
end
(注意:如果您使用Rails 3,您必须将上面的
脚本/控制台
更改为
Rails控制台
,但是这还没有经过测试,因为我还没有在我们的项目中使用Rails 3)

cap-t

cap invoke                        # Invoke a single command on the remote ser...
cap shell                         # Begin an interactive Capistrano session.
cap-e调用

------------------------------------------------------------
cap invoke
------------------------------------------------------------
Invoke a single command on the remote servers. This is useful for performing
one-off commands that may not require a full task to be written for them. Simply
specify the command to execute via the COMMAND environment variable. To execute
the command only on certain roles, specify the ROLES environment variable as a
comma-delimited list of role names. Alternatively, you can specify the HOSTS
environment variable as a comma-delimited list of hostnames to execute the task
on those hosts, explicitly. Lastly, if you want to execute the command via sudo,
specify a non-empty value for the SUDO environment variable.

Sample usage:

  $ cap COMMAND=uptime HOSTS=foo.capistano.test invoke
  $ cap ROLES=app,web SUDO=1 COMMAND="tail -f /var/log/messages" invoke
这篇文章有一个很好的解决方案。我只是做了一个小改动,使它可以在多服务器设置中工作

  desc "open remote console (only on the last machine from the :app roles)"
  task :console, :roles => :app do
    server = find_servers_for_task(current_task).last
    input = ''

    run "cd #{current_path} && ./script/console #{rails_env}", :hosts => server.host do |channel, stream, data|
      next if data.chomp == input.chomp || data.chomp == ''
      print data
      channel.send_data(input = $stdin.gets) if data =~ /^(>|\?)>/
    end
  end

不过,你得到的终端并不令人惊讶。如果有人有一些改进可以使CTRL-D和CTRL-H或箭头正常工作,请发布。

我发现基于


这就是我在没有Capistrano(一个构建在rake任务之上的部署工具)的情况下如何做到的。我在自述文件中添加了一项任务,用于在服务器上打开远程控制台:

# remote.rake
namespace :remote do

desc "Open rails console on server"
task :console do
  require 'remoting/task'

  remote('console', config.login, :interactive => true) do
    cd config.dest
    source '$HOME/.rvm/scripts/rvm'
    bundle :exec, "rails c production"
  end
end

end
我跑不了

$ rake remote:console

我非常喜欢中显示的“仅使用现有工具”方法。它只是使用SSH shell命令,而不是自己实现交互式SSH shell,这可能会在irb更改其默认提示时中断,您需要切换用户或任何其他疯狂的事情发生。

Rails控制台是一个交互式提示,如果您只想运行一段代码,例如快速修复,您可以通过rails3的
script/runner
rails runner
来完成。如果您不知道,
runner
将加载整个环境,就像
控制台
或依赖于
rake
任务:环境
感谢Swand…问题是我需要交互性来诊断应用程序逻辑在生产数据或生产环境中遇到的问题,我无法在本地复制。您可以尝试“cap-v shell”或添加“默认运行选项[:shell]=false“在capfile中?谢谢,invoke的问题是您无法获得所需的交互式会话。shell更有前途,问题是当你调用控制台时它会挂起,我在上面添加了它。太棒了!谁需要希罗库?要是墨西哥的互联网不是一个无赖就好了。一切都进行得非常顺利,除了我没有一个“舞台”环境,只是不得不移除它,它就像一个魔咒。只是一个说明,需要一个带有readline的ruby的特殊版本:`
require':libreadline。所以。5:无法打开共享对象文件:没有这样的文件或目录
`
# remote.rake
namespace :remote do

desc "Open rails console on server"
task :console do
  require 'remoting/task'

  remote('console', config.login, :interactive => true) do
    cd config.dest
    source '$HOME/.rvm/scripts/rvm'
    bundle :exec, "rails c production"
  end
end

end
$ rake remote:console