【问题标题】:Capistrano fails to deploy to remote serverCapistrano 无法部署到远程服务器
【发布时间】:2011-09-13 00:01:00
【问题描述】:

解决方案

解决方案是将以下内容添加到 production.rb 的顶部:

$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
require "rvm/capistrano"                  # Load RVM's capistrano plugin.
set :rvm_ruby_string, '1.9.2@rails31dataserver'        # Or whatever env you want it to run in.
set :rvm_bin_path, '/usr/local/rvm/bin'

我之前缺少的部分是set :rvm_bin_path, '/usr/local/rvm/bin',因为我以前从未在 Capistrano 部署中使用过该配置设置,我已经做过一些。哦,好吧,一天之内的工作。归功于 irc.freenode.net 上 #rvm 频道中的 tonyflint!

原帖

悬崖笔记

  • 我正在运行 RVM 的系统安装
  • 我正在通过 Capistrano 进行部署

我现在傻眼了。基本上发生的事情是我试图通过 Capistrano 进行部署,但它失败了,很难。这是我的 deploy.rb 和 production.rb 文件的摘要(我正在做一个多阶段环境并省略 staging.rb 文件,因为它工作正常)。 http://pastie.org/2523675

这是cap production deploy:setup的输出:

$ cap production deploy:setup
  * executing `production'
    triggering start callbacks for `deploy:setup'
  * executing `multistage:ensure'
  * executing `deploy:setup'
  * executing "sudo -p 'sudo password: ' mkdir -p /var/www/html/dataserver /var/www/html/dataserver/releases /var/www/html/dataserver/shared /var/www/html/dataserver/shared/system /var/www/html/dataserver/shared/log /var/www/html/dataserver/shared/pids"
    servers: ["omitted"]
Password: 
    [omitted] executing command
*** [err :: omitted] sudo
*** [err :: omitted] :
*** [err :: omitted] sorry, you must have a tty to run sudo
*** [err :: omitted] 
    command finished in 60ms
failed: "sh -c 'sudo -p '\\''sudo password: '\\'' mkdir -p /var/www/html/dataserver /var/www/html/dataserver/releases /var/www/html/dataserver/shared /var/www/html/dataserver/shared/system /var/www/html/dataserver/shared/log /var/www/html/dataserver/shared/pids'" on omitted

现在,我明白为什么会这样了。我正在远程尝试使用 sudo,这是一个安全禁忌。所以,这意味着我需要使用default_run_options[:pty] = true。所以我取消注释并再次运行cap production deploy:setup,一切都运行得很好。部署的目录结构得到设置和一切。惊人的。现在我尝试运行cap production deploy,输出如下:

$ cap production deploy
  * executing `production'
    triggering start callbacks for `deploy'
  * executing `multistage:ensure'
  * executing `deploy'
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "hg log -r default --template '{node|short}'"
    command finished in 52ms
  * executing "if [ -d /var/www/html/dataserver/shared/cached-copy ]; then hg pull --repository /var/www/html/dataserver/shared/cached-copy https://cowfish.unh.edu/hg/DataServerApp && hg update --repository /var/www/html/dataserver/shared/cached-copy --clean 6979cec4fc00; else hg clone --noupdate https://cowfish.unh.edu/hg/DataServerApp /var/www/html/dataserver/shared/cached-copy && hg update --repository /var/www/html/dataserver/shared/cached-copy --clean 6979cec4fc00; fi"
    servers: ["omitted"]
Password: 
    [omitted] executing command
 ** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
 ** [omitted :: out] http authorization required
 ** [omitted :: out] realm: Mercurial Project Repository
 ** [omitted :: out] user:
 ** [omitted :: out] d
 ** [omitted :: out] e
 ** [omitted :: out] p
 ** [omitted :: out] l
 ** [omitted :: out] o
 ** [omitted :: out] y
 ** [omitted :: out]
 ** [omitted :: out] password:
 ** [omitted :: out]
 ** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
 ** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
 ** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
 ** [omitted :: out] requesting all changes
 ** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
 ** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
 ** [omitted :: out] adding changesets
 ** [omitted :: out] adding manifests
 ** adding file changes
 ** [omitted :: out] added 11 changesets with 187 changes to 125 files
 ** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
 ** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
 ** [omitted :: out] 114 files updated, 0 files merged, 0 files removed, 0 files unresolved
    command finished in 1332ms
    copying the cached version to /var/www/html/dataserver/releases/20110912233835
  * executing "cp -RPp /var/www/html/dataserver/shared/cached-copy /var/www/html/dataserver/releases/20110912233835 && (echo 6979cec4fc00 > /var/www/html/dataserver/releases/20110912233835/REVISION)"
    servers: ["omitted"]
    [omitted] executing command
    command finished in 23ms
  * executing `deploy:finalize_update'
  * executing "chmod -R g+w /var/www/html/dataserver/releases/20110912233835"
    servers: ["omitted"]
    [omitted] executing command
    command finished in 7ms
  * executing "rm -rf /var/www/html/dataserver/releases/20110912233835/log /var/www/html/dataserver/releases/20110912233835/public/system /var/www/html/dataserver/releases/20110912233835/tmp/pids &&\\\n      mkdir -p /var/www/html/dataserver/releases/20110912233835/public &&\\\n      mkdir -p /var/www/html/dataserver/releases/20110912233835/tmp &&\\\n      ln -s /var/www/html/dataserver/shared/log /var/www/html/dataserver/releases/20110912233835/log &&\\\n      ln -s /var/www/html/dataserver/shared/system /var/www/html/dataserver/releases/20110912233835/public/system &&\\\n      ln -s /var/www/html/dataserver/shared/pids /var/www/html/dataserver/releases/20110912233835/tmp/pids"
    servers: ["omitted"]
    [omitted] executing command
    command finished in 8ms
  * executing "find /var/www/html/dataserver/releases/20110912233835/public/images /var/www/html/dataserver/releases/20110912233835/public/stylesheets /var/www/html/dataserver/releases/20110912233835/public/javascripts -exec touch -t 201109122338.35 {} ';'; true"
    servers: ["omitted"]
    [omitted] executing command
 ** [out :: omitted] find: /var/www/html/dataserver/releases/20110912233835/public/images: No such file or directory
 ** [out :: omitted] find: /var/www/html/dataserver/releases/20110912233835/public/stylesheets: No such file or directory
 ** [out :: omitted] find: /var/www/html/dataserver/releases/20110912233835/public/javascripts: No such file or directory
    command finished in 6ms
  * executing `deploy:symlink'
  * executing "rm -f /var/www/html/dataserver/current && ln -s /var/www/html/dataserver/releases/20110912233835 /var/www/html/dataserver/current"
    servers: ["omitted"]
    [omitted] executing command
    command finished in 6ms
 ** transaction: commit
  * executing `deploy:restart'
  * executing "sudo -p 'sudo password: ' touch /var/www/html/dataserver/current/tmp/restart.txt"
    servers: ["omitted"]
    [omitted] executing command
    command finished in 10ms
    triggering after callbacks for `deploy'
  * executing `deploy:migrate'
    triggering before callbacks for `deploy:migrate'
  * executing `sqlite3:link_configuration_file'
  * executing "ln -nsf /var/www/html/dataserver/shared/sqlite_config.yml /var/www/html/dataserver/releases/20110912233835/config/database.yml"
    servers: ["omitted"]
    [omitted] executing command
    command finished in 6ms
  * executing "cd /var/www/html/dataserver/releases/20110912233835 && rake RAILS_ENV=production  db:migrate"
    servers: ["omitted"]
    [omitted] executing command
 ** [out :: omitted] sh: rake: command not found
    command finished in 5ms
failed: "sh -c 'cd /var/www/html/dataserver/releases/20110912233835 && rake RAILS_ENV=production  db:migrate'" on omitted

所以看起来它加载的任何环境都看不到rake。要查看路径中加载了什么,我创建了一个部署任务,输出如下:

$ cap production test_path
  * executing `production'
    triggering start callbacks for `test_path'
  * executing `multistage:ensure'
  * executing `test_path'
  * executing "echo $PATH"
    servers: ["omitted"]
Password: 
    [omitted] executing command
 ** [out :: omitted] /usr/local/bin:/bin:/usr/bin
    command finished in 11ms
  * executing "echo $rvm_path"
    servers: ["omitted"]
    [omitted] executing command
 ** [out :: omitted] 
    command finished in 5ms

现在您会注意到路径肯定不正确。对于正在建立会话的用户,它应该是:

/usr/local/rvm/gems/ruby-1.9.2-p290@rails31dataserver/bin:/usr/local/rvm/gems/ruby-1.9.2-p290@global/bin:/usr/local/rvm/rubies/ruby-1.9.2-p290/bin:/usr/local/rvm/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/lpeabody/bin

再一次,我明白为什么这不起作用了。这是因为因为我正在运行default_run_options[:pty] = true,所以我的环境正在加载,至少这是我目前的理论。所以,毕竟,我得到了结论 - 我需要以某种方式加载我的环境,以便 rake 可以在不远程启用 sudo 的情况下运行。

现在,我知道我不是唯一需要这样做的人,因此我们将不胜感激任何指针或提示。现在我已经绞尽脑汁 8 个小时了,我需要尽快部署这个应用程序。

【问题讨论】:

    标签: ruby-on-rails permissions rvm capistrano


    【解决方案1】:

    解决方案是将以下内容添加到 production.rb 的顶部:

    $:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
    require "rvm/capistrano"                  # Load RVM's capistrano plugin.
    set :rvm_ruby_string, '1.9.2@rails31dataserver'        # Or whatever env you want it to run in.
    set :rvm_bin_path, '/usr/local/rvm/bin'
    

    我之前缺少的部分是set :rvm_bin_path, '/usr/local/rvm/bin',因为我之前从未在 Capistrano 部署中使用过该配置设置,我已经做过一些。哦,好吧,一天之内的工作。归功于 irc.freenode.net 上 #rvm 频道中的 tonyflint!

    【讨论】:

      【解决方案2】:

      确保你运行:

      gem install rvm-capistrano
      

      在你放之前

      require "rvm/capistrano" in your "deploy.rb"
      

      我这样做之后,它就起作用了。

      【讨论】:

        【解决方案3】:

        在您的 capfile 中可以尝试的一些事情(这些用于系统范围的 RVM 安装,不适用于每个用户的安装。)

        require "rvm/capistrano"
        set :rvm_bin_path, "/usr/local/rvm/bin"
        $:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
        

        【讨论】:

          【解决方案4】:

          就我而言,添加

          default_run_options[:pty] = true
          

          解决了这个问题。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2016-07-21
            • 2011-08-26
            • 1970-01-01
            • 1970-01-01
            • 2014-05-26
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多