【问题标题】:Cap deploy:setup stuck at sftp command (using Simone Carletti's recipe for database.yml)Cap deploy:setup 停留在 sftp 命令(使用 Simone Carletti 的 database.yml 配方)
【发布时间】:2014-01-07 08:28:37
【问题描述】:

我正在使用 capistrano 部署我的 rails 3 应用程序,但我无法弄清楚为什么在 cap deploy:setup 任务期间的某个时刻命令行正在等待 sftp 命令。

我搜索了发送此命令的配方以了解但找不到。

作为旁注,我使用 Simon Carlett's recipe 来生成 database.yml 文件,而不是在 github 上存储和获取它)。

这是我的输出:

/var/www/odpf/config$ cap deploy:setup
    triggering load callbacks
  * 2014-01-07 09:03:03 executing `deploy:setup'
  * executing "mkdir -p /var/www/odpf /var/www/odpf/releases /var/www/odpf/shared /var/www/odpf/shared/system /var/www/odpf/shared/log /var/www/odpf/shared/pids"
    servers: ["*****"]
Enter passphrase for /home/me/.ssh/id_rsa: 
    [*****] executing command
 ** [out :: *****]
    command finished in 355ms
    triggering after callbacks for `deploy:setup'
  * 2014-01-07 09:03:12 executing `deploy:db:setup'
  * executing "mkdir -p /var/www/odpf/shared/db"
    servers: ["*****"]
    [*****] executing command
 ** [out :: *****]
    command finished in 350ms
  * executing "mkdir -p /var/www/odpf/shared/config"
    servers: ["*****"]
    [*****] executing command
 ** [out :: *****]
    command finished in 350ms
    servers: ["*****"]
 ** sftp upload #<StringIO:0x000000010579f8> -> /var/www/odpf/shared/config/database.yml

在最后一条指令之后,命令行似乎无限等待...... 我点击 CTRL+C 并输出了一些 ruby​​ 错误:

^C/home/me/.rvm/gems/ruby-2.1.0@rails3/gems/capistrano-2.15.5/lib/capistrano/processable.rb:25:in `select': Interrupt
etc...

我在第 25 行查看了这个文件,发现了这个:

  21> readers = sessions.map { |session| session.listeners.keys }.flatten.reject { |io| io.closed? }
  22> writers = readers.select { |io| io.respond_to?(:pending_write?) && io.pending_write? }
  23>
  24> if readers.any? || writers.any?
  25>   readers, writers, = IO.select(readers, writers, nil, wait)
  26> else
  27>   return false
  28> end

这是 Simone Carletti 的食谱:

#
# = Capistrano database.yml task
#
# Provides a couple of tasks for creating the database.yml
# configuration file dynamically when deploy:setup is run.
#
# Category::    Capistrano
# Package::     Database
# Author::      Simone Carletti
# Copyright::   2007-2009 The Authors
# License::     MIT License
# Link::        http://www.simonecarletti.com/
# Source::      http://gist.github.com/2769
#
#

unless Capistrano::Configuration.respond_to?(:instance)
  abort "This extension requires Capistrano 2"
end

Capistrano::Configuration.instance.load do

  namespace :db do

    desc <<-DESC
      Creates the database.yml configuration file in shared path.

      By default, this task uses a template unless a template
      called database.yml.erb is found either is :template_dir
      or /config/deploy folders. The default template matches
      the template for config/database.yml file shipped with Rails.

      When this recipe is loaded, db:setup is automatically configured
      to be invoked after deploy:setup. You can skip this task setting
      the variable :skip_db_setup to true. This is especially useful
      if you are using this recipe in combination with
      capistrano-ext/multistaging to avoid multiple db:setup calls
      when running deploy:setup for all stages one by one.
    DESC
    task :setup, :except => { :no_release => true } do

      default_template = <<-EOF
      base: &base
        adapter: sqlite3
        timeout: 5000
      development:
        database: #{shared_path}/db/development.sqlite3
        <<: *base
      test:
        database: #{shared_path}/db/test.sqlite3
        <<: *base
      production:
        database: #{shared_path}/db/production.sqlite3
        <<: *base
      EOF

      location = fetch(:template_dir, "config/deploy") + '/database.yml.erb'
      template = File.file?(location) ? File.read(location) : default_template

      config = ERB.new(template)

      run "mkdir -p #{shared_path}/db"
      run "mkdir -p #{shared_path}/config"
      put config.result(binding), "#{shared_path}/config/database.yml"
    end

    desc <<-DESC
      [internal] Updates the symlink for database.yml file to the just deployed release.
    DESC
    task :symlink, :except => { :no_release => true } do
      run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
    end

  end

  after "deploy:setup",           "db:setup"   unless fetch(:skip_db_setup, false)
  after "deploy:finalize_update", "db:symlink"

end

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: ruby-on-rails-3 capistrano


    【解决方案1】:

    经过长时间的搜索,我决定升级到 Capistrano 3.x,认为它可能会解决我的问题,因为它使用 ssh-kit 而不是 sftp。

    它没有解决这个问题。

    我打开了一个链接到 Capistrano 3.x 的新 question 并找到了解决方案。

    这可能也是 Capistrano 2.x 的解决方案,虽然我没有测试过。所以我在这里发布这个可能的解决方案,以防有人有兴趣测试它。

    事实上,在 Capistrano 3.x 中,问题与自 2000 年以来一直存在的错误有关。因此,sftp 的工作方式可能与 net-scp 相同。

    问题来自我的 .bashrc 文件(以及我放入的 echo 命令),该文件在 ssh 连接(非登录、非交互)期间执行。 更多信息here

    如果有人测试成功,请告诉我们。

    我的几分钱。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多