【问题标题】:Whenever Gem Fails to Run "bundle exec" Correctly in Capistrano每当 Gem 无法在 Capistrano 中正确运行“bundle exec”时
【发布时间】:2013-01-24 22:08:47
【问题描述】:

我在使用 Capistrano 将Whenever gem 部署到我的生产环境时遇到问题。

问题源于 bundle exec whenever 命令触发了一些“缺少 gem”问题(但从 shell 运行 bundle install 表明一切都在那里!)。

我的感觉是两种情况之一正在发生:在调用 bundle exec 之前 Bundler 没有完全加载,或者在错误的位置运行它的路径问题。

这是怎么回事:

  * executing `deploy'
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
    executing locally: "git ls-remote git@my-source-repository:mysource.git HEAD"
    command finished in 1847ms
  * executing "git clone -q git@my-source-repository:mysource.git /domains/myapp/releases/20130124211036 && cd /domains/myapp/releases/20130124211036 && git checkout -q -b deploy 90238bbcb993e3e7df2374ffaa13e7ed701c202e && (echo 90238bbcb993e3e7df2374ffaa13e7ed701c202e > /domains/myapp/releases/20130124211036/REVISION)"
    servers: ["myip"]
    [myip] executing command
 ** [myip :: out] Enter passphrase for key '/home/deploy/.ssh/id_rsa':
 ** [myip :: out]
    command finished in 9294ms
  * executing `deploy:finalize_update'
    triggering before callbacks for `deploy:finalize_update'
  * executing `whenever:update_crontab'
  * executing "cd /domains/myapp/releases/20130124211036 && bundle exec whenever --update-crontab My App --set environment=production --roles db"
    servers: ["myip"]
    [myip] executing command
 ** [out :: myip] Could not find carrierwave-0.5.8 in any of the sources
 ** [out :: myip] Run `bundle install` to install missing gems.
    command finished in 1967ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /domains/myapp/releases/20130124211036; true"
    servers: ["myip"]
    [myip] executing command
    command finished in 998ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.3' -c 'cd /domains/myapp/releases/20130124211036 && bundle exec whenever --update-crontab My App --set environment=production --roles db'" on myip

您可以看到失败来自这一行:

bundle exec whenever --update-crontab

这又由我的 Capistrano deploy.rb 运行。

# Your Application's "Name"
set :application, [My App]

# The URL to your application's repository
set :repository, [repo]
set :scm, :git
set :scm_passphrase, [password]

# The user you are using to deploy with (This user should have SSH access to your server)
set :user, "deploy"

# We want to deploy everything under your user, and we don't want to use sudo
set :use_sudo, false

# Where to deploy your application to.
set :deploy_to, "/domains/myapp/"

# Load RVM's capistrano plugin.    
require "rvm/capistrano"

set :rvm_ruby_string, '1.9.3'
set :rvm_type, :system  # use system-wide RVM

# Require that we use bundler to install necessary gem dependencies
require "bundler/capistrano"

set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"


# -------------------------------- Server Definitions --------------------------------
# Define the hostname of your server.  If you have multiple servers for multiple purposes, we can define those below as well.
set :server_name, [server]

# We're assuming you're using a single server for your site, but if you have a seperate asset server or database server, you can specify that here.
role :app, server_name
role :web, server_name
role :db,  server_name, :primary => true

# -------------------------------- Final Config --------------------------------
# This configuration option is helpful when using svn+ssh but doesn't hurt anything to leave it enabled always.
default_run_options[:pty] = true 

namespace :deploy do
  desc "Tell Passenger to restart the app."
  task :restart do
    run "touch #{deploy_to}current/tmp/restart.txt"
  end

  task :start do
    run "cd #{deploy_to} && ln -s current/public public_html"
    run "touch #{deploy_to}current/tmp/restart.txt"
  end

  task :symlink do
    run "cd #{deploy_to} && rm current ; ln -s releases/#{release_name} current"
  end

  task :stop do
    run "rm #{deploy_to}public_html"
  end

  namespace :web do
    task :disable do
      run "cd #{deploy_to} && rm public_html && ln -s static_site public_html"
    end

    task :enable do
      run "cd #{deploy_to} && rm public_html && ln -s current/public public_html"
    end
  end


  desc "Symlink shared configs and folders on each release."
  task :symlink_shared do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
    run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"

    # create symlink to uploads folder for Carrierwave resources (i.e., book cover images)
    run "ln -nfs #{shared_path}/uploads  #{release_path}/public/uploads"
  end

  desc "Sync the public/assets directory."
  task :assets do
    system "rsync -vr --exclude='.DS_Store' public/assets #{user}@#{application}:#{shared_path}/"
  end

end

after "deploy", "deploy:migrate"

after 'deploy:update_code', 'deploy:symlink_shared'

after(:setup) do
  run "rm -rf #{deploy_to}public_html"
  run "mkdir #{deploy_to}static_site"
end

现在,我得到的有关 CarrierWave 的错误是虚假的 - 我已经使用 CarrierWave 很长时间了 - 问题显然源于(正如您通过触发错误的命令所看到的)来自无论何时本身或 Bundler .

我认为它实际上可能与与 RVM 相关的路径有关。无论如何,bundle exec whenever 不起作用。

有什么想法吗?

【问题讨论】:

  • 您是否尝试过设置和使用 binstubs?
  • 刚刚开始遇到完全相同的问题。我使用的是 RBenv,而不是 RVM,但我也认为这是一个环境问题。我尝试将命令切换到rbenv exec bundle exec whenever 并且还设置了:default_environment,但无济于事。我正在使用无论何时-0.8.1。

标签: ruby-on-rails ruby-on-rails-3 capistrano bundler whenever


【解决方案1】:

事实证明存在几个问题,这两个问题都需要解决:

  • 每当 ~> 0.8 引入了 Capistrano 角色的错误
  • 无论何时 cap 任务在 bundle:install 之前触发(这在您上面的代码中得到确认)

在此处查看问题:https://github.com/javan/whenever/issues/275 和此处:https://github.com/javan/whenever/issues/269

要解决问题,您很可能需要

  • 在您的服务器上更新捆绑程序 (-v 1.2.3)
  • 在本地更新捆绑程序
  • 随时更新到最新版本 (-v 0.8.2)

【讨论】:

  • 太棒了。非常感谢您找到这些。我松了一口气,这不仅仅是我自己的愚蠢,而且修复就像确保一切都是最新的一样简单。谢谢一百万!
  • 没问题!当你遇到的时候,我遇到的几乎是正确的——看起来我们并不孤单。
  • 太好了,这也是我更新rails后需要做的。
【解决方案2】:

@ideaoforder 的回答对我也有帮助,虽然之前我遇到了同样的问题,因为require 'whenever/capistrano' 位于config/deploy.rb 的顶部,然后是require 'bundler/capistrano'。交换这两个有帮助。

我有require 'bundler/capistrano' 作为规则总是在部署脚本的顶部。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 2013-11-12
    • 2014-07-01
    • 1970-01-01
    相关资源
    最近更新 更多