Rails cron随时,bundle:找不到命令

Jos*_*der 45 cron ruby-on-rails whenever

我试图使用每天执行rake任务onces一天.我得到这个错误

/bin/bash: bundle: command not found
/home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find bundler (>= 0) amongst [minitest-1.6.0, rake-0.8.7, rdoc-2.5.8] (Gem::LoadError)
        from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
        from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
        from /home/app/.rvm/gems/ruby-1.9.2-p180/bin/bundle:18:in `<main>'
Run Code Online (Sandbox Code Playgroud)

这是我的crontab

# Begin Whenever generated tasks for: /home/af/www/app/releases/20120216172204/config/schedule.rb
PATH=/home/af/.rvm/gems/ruby-1.9.2-p180@global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

0 0 * * * /bin/bash -l -c 'cd /home/af/www/app/releases/20120216172204 && rvm 1.9.1-p180; RAILS_ENV=production /home/af/.rvm/gems/ruby-1.9.2-p180/bin/bundle exec rake daily:stats --silent >> /home/af/www/app/releases/20120216172204/log/cron.log 2>&1'

# End Whenever generated tasks for: /home/af/www/app/releases/20120216172204/config/schedule.rb
Run Code Online (Sandbox Code Playgroud)

我不知道为什么它不起作用.如果我运行命令:

cd /home/af/www/app/releases/20120216172204 && rvm 1.9.1-p180; RAILS_ENV=production /home/af/.rvm/gems/ruby-1.9.2-p180/bin/bundle exec rake daily:stats --silent >> /home/af/www/app/releases/20120216172204/log/cron.log 2>&1
Run Code Online (Sandbox Code Playgroud)

它工作正常,不知道这里发生了什么.

小智 59

您还可以通过将以下内容放在schedule.rb文件的顶部来确保您的PATH最终在crontab中:

env :PATH, ENV['PATH']
Run Code Online (Sandbox Code Playgroud)

https://groups.google.com/forum/#!msg/whenever-gem/yRLt3f2jrfU/Exu3xfCo8DAJ

如果上述解决方案不适合您,请尝试:

env :GEM_PATH, ENV['GEM_PATH']
Run Code Online (Sandbox Code Playgroud)

  • 以防万一.这对我有用,但后来找不到我的宝石文件.我用`env:GEM_PATH,ENV ['GEM_PATH']`修复它 (7认同)
  • 这对我不起作用 - 你能尝试删除 env :PATH, ENV['PATH'] 并确认这实际上是一个修复吗? (2认同)

Sum*_*not 6

就我而言,我只是跑了:

rvm env --path -- ruby-version[@gemset-name]
Run Code Online (Sandbox Code Playgroud)

参考cron 作业设置文档

在命令中的 bundle 命令之前为 ruby​​ 路径的命令添加了新的源代码行 crontab -e

source /usr/local/rvm/environments/ruby-1.9.3-p392;
Run Code Online (Sandbox Code Playgroud)

现在命令如下:

前:

0 4 * * * cd /home/current && bundle exec rake my_rake RAILS_ENV=production
Run Code Online (Sandbox Code Playgroud)

后:

0 4 * * * cd /home/current && source /usr/local/rvm/environments/ruby-1.9.3-p392; bundle exec rake my_rake RAILS_ENV=production
Run Code Online (Sandbox Code Playgroud)

干杯!!!


Jos*_*der 1

我整个下午都在玩这个,找不到更好的解决方案。这是我想出的

bundle install --binstubs
Run Code Online (Sandbox Code Playgroud)

然后运行

bin/rake daily:stats
Run Code Online (Sandbox Code Playgroud)

  • 您是否尝试过丹尼斯的建议,将 env :PATH, ENV['PATH'] 添加到您的 Schedule.rb 中?这对我有用。 (2认同)