【发布时间】:2019-03-23 00:48:03
【问题描述】:
操作系统:Ubuntu 安装在 docker 上,普通 ubuntu 安装在我的个人笔记本电脑上。
我正在运行这个 cron 作业:
*/5 * * * * /bin/bash -l -c "cd /home/deploy/railsapp && rake spec >> cron.log 2>&1"
我已经尝试过使用 bundle exec rake 规范,没有 /bin/bash,使用任何 gem,使用 /usr/local/bin/rake 规范,但除了这些错误之外什么都没有发生。
运行 cron 作业时日志文件中的错误:
/bin/bash: bundle: command not found
/bin/bash: rake: command not found
rake aborted!
Bundler::GemNotFound: Could not find rake-11.2.2 in any of the sources
/home/deploy/railsapp/config/boot.rb:3:in `<top (required)>'
/home/deploy/railsapp/config/application.rb:1:in `<top (required)>'
/home/deploy/railsapp/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/home/deploy/railsapp/config/boot.rb:3:in `<top (required)>'
/home/deploy/railsapp/config/application.rb:1:in `<top (required)>'
/home/deploy/railsapp/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
bundler: failed to load command: rake (/usr/local/bin/rake)
Bundler::GemNotFound: Could not find rake-11.2.2 in any of the sources
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:95:in `block in materialize'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `map!'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `materialize'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:140:in `specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:185:in `specs_for'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:174:in `requested_specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/environment.rb:19:in `requested_specs'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:14:in `setup'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:95:in `setup'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/setup.rb:19:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
从命令行手动运行rake spec 时它工作正常,但从 cron 中它给出了这个错误。
有什么想法吗?
【问题讨论】:
-
您是否使用同一用户运行 cron?看起来正在运行的用户 cron 无权访问所需的 gem。
-
您好,感谢您的回答,它以root身份运行,操作系统中没有用户..它只有root用户,作为docker内的容器运行
-
也许 docker 是问题的原因?尝试为问题添加
docker标签并在问题文本中写下它。 -
它在我的本地机器上给出了同样的错误,所以 docker 与它无关。
标签: ruby-on-rails cron rake