每当给``require':无法在生产服务器中加载这样的文件 - bundler / setup`错误

时间:2015-05-19 11:47:45

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

我试图在我的Ubuntu 14.04服务器中设置gem。在我的本地机器上它工作正常。我使用capistrano来部署网站。我在服务器中使用rbenv。但是在安装乘客时,它会安装我不使用的Ruby 1.9。只使用rbenv。这是我的shcedule.rb:

set :output, "#{path}/log/cron.log"

every 30.minutes do
    runner 'UploadmailWorker.perform_async'
end

every 12.hours do
    runner 'SubscriptionWorker.perform_async'
end

every :month do
    runner 'PaysellerWorker.perform_async'
end

我的deploy.rb:

set :default_environment, {
  'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}

set :whenever_roles,        ->{ :app }
set :whenever_command,      ->{ [:bundle, :exec, :whenever] }
set :whenever_command_environment_variables, ->{ {} }
set :whenever_identifier,   ->{ fetch :application }
set :whenever_environment,  ->{ fetch :rails_env, fetch(:stage, "production") }
set :whenever_variables,    ->{ "environment=#{fetch :whenever_environment}" }
set :whenever_update_flags, ->{ "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" }
set :whenever_clear_flags,  ->{ "--clear-crontab #{fetch :whenever_identifier}" }

namespace :deploy do

    desc 'Restart application'
    task :restart do
        on roles(:app), in: :sequence, wait: 5 do
            execute :touch, release_path.join('tmp/restart.txt')
        end
    end

    after :publishing, 'deploy:restart'
    after :finishing, 'deploy:cleanup'
end

部署后,无论何时都不起作用。在cron.log中我发现了这个错误:

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- bundler/setup (LoadError)
        from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/deploy/istockseller/releases/20150519112817/config/boot.rb:3:in `<top (required)>'
        from bin/rails:7:in `require_relative'
        from bin/rails:7:in `<main>'

我该如何解决?

2 个答案:

答案 0 :(得分:2)

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in'requiret'

不要被这条线弄糊涂。这是可以为每个ubuntu实例安装的ruby库,因此您可以执行ruby命令。

你需要cd来项目并安装bundler。

运行此。

cd /to/your/project
[sudo] gem install bundler
bundle install

更新rbenv的信息

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

在Ubuntu上使用〜/ .bashrc,或在〜/ .zshrc上使用Zsh

$ type rbenv
#=> "rbenv is a function"

答案 1 :(得分:0)

我也有这个错误:

custom_require.rb:36:in `require': cannot load such file -- bundler/setup (LoadError)

在调查问题后,PATH shell变量在cronb作业中有所不同,并且没有rbenv内容

使用crontab -e

手动更改了crontab

并在crontab行添加

... && PATH = my_complete_path RAILS_ENV=production  bin/rails ... ... 
之后,cronjob开始工作......

我不认为这是一个很好的答案,但是要让它发挥作用。也许它有助于某人。