capistrano和cron中的耙任务使用错误的红宝石版本

问题描述 投票:0回答:1

我需要在部署过程中执行rake任务。为此,我在deploy名称空间中有一个任务:

desc 'Start Telegram server'
task :start_telegram do
  on roles(:app) do
    puts "Current path: #{release_path}"
    within release_path do
      with rails_env: fetch(:rails_env) do
        execute :nohup, "bundle exec rake bot:start_poller > #{shared_path}/log/telegram.log 2>&1 & echo $! > #{shared_path}/tmp/pids/telegram-server.pid"
      end
    end
  end
end

它是这样执行的:after :stop_telegram, :start_telegram。日志文件的输出是:

/var/lib/gems/2.3.0/gems/bundler-2.0.2/lib/bundler/spec_set.rb:87:in `block in materialize': Could not find nokogiri-1.10.3 in any of the sources (Bundler::GemNotFound)
        from /var/lib/gems/2.3.0/gems/bundler-2.0.2/lib/bundler/spec_set.rb:81:in `map!'
        from /var/lib/gems/2.3.0/gems/bundler-2.0.2/lib/bundler/spec_set.rb:81:in `materialize'
        from /var/lib/gems/2.3.0/gems/bundler-2.0.2/lib/bundler/definition.rb:170:in `specs'
        from /var/lib/gems/2.3.0/gems/bundler-2.0.2/lib/bundler/definition.rb:237:in `specs_for'
        from /var/lib/gems/2.3.0/gems/bundler-2.0.2/lib/bundler/definition.rb:226:in `requested_specs'
        from /var/lib/gems/2.3.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:108:in `block in definition_method'
        from /var/lib/gems/2.3.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:20:in `setup'
        from /var/lib/gems/2.3.0/gems/bundler-2.0.2/lib/bundler.rb:107:in `setup'
        from /var/lib/gems/2.3.0/gems/bundler-2.0.2/lib/bundler/setup.rb:20:in `<top (required)>'
        from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'

rbenv ruby​​版本是2.5.3,ruby -v给了我ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux],但我不知道为什么它会出现在/usr/lib/gems/2.3.0中。当cron执行rake任务时,也会发生相同的情况。关于什么是错的任何想法?谢谢你。

编辑:如果我在服务器RAILS_ENV=production nohup bundle exec rake bot:start_poller > /home/deployer/apps/aws-rails/www/shared/log/telegram.log 2>&1 & echo $! > /home/deployer/apps/aws-rails/www/shared/tmp/pids/telegram-server.pid上手动执行它,则一切正常。

ruby-on-rails rake capistrano rbenv
1个回答
0
投票

如果要Capistrano使用rvm版本,则需要使用rvm-capistrano gem。

set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"")  

有关更多详细信息,请检查下面的链接

https://rvm.io/integration/capistrano#gem

© www.soinside.com 2019 - 2024. All rights reserved.