【问题标题】:Rake Cron job errorRake Cron 作业错误
【发布时间】:2013-01-25 08:51:18
【问题描述】:

0/5 * * * * /bin/bash -l -c 'cd /home/mss/ruby/example && RAILS_ENV=development /usr/local/bin/bundle exec rake check_me_out --silent >> /tmp/cron_log.日志 2>&1'

上面的 cron 抛出错误“bash: bundle: command not found...”

该命令在命令行中运行正常

任何帮助将不胜感激。

【问题讨论】:

  • 在直接跳入代码之前,您有什么上下文吗?
  • 我假设运行 cron 作业的用户不知道命令 bundle 或无权访问它。
  • 试图在 Rails 中搜索任务。请参阅上面的 cmets,我可以从命令行运行它而没有任何问题,但不能从 cron 运行。

标签: ruby-on-rails cron rake


【解决方案1】:

好的,所以我得到了这个工作。 Cron 不加载配置文件设置。我必须将 bash_profile 作为命令的一部分加载,现在它可以工作了。

0/5 * * * * /bin/bash -l -c 'source ~/.bash_profile && cd /home/mss/ruby/example && RAILS_ENV=development bin/rake check_me_out --silent >> /tmp/cron_log.log 2>&1'

【讨论】:

  • 在这个答案中添加一些东西,最好使用 $HOME/.bash_profile (或 .profile 取决于您的版本)而不是 ~/.bash_profile :)
【解决方案2】:

我遇到了同样的问题。

在 CRON 中设置正确的 RVM 路径时我​​已经解决了:

** * * * /bin/bash -l -c 'cd /home/alex/Projects/my_app && source ~/.bash_profile && rvm use ruby​​-1.9.3-p194-perf && bundle exec rake RAILS_ENV=开发 my_tasks --silent >> /tmp/cron_log.log 2>&1'

【讨论】:

    【解决方案3】:

    我在 AWS EC2 服务器上设置 cron 时也遇到了同样的问题。它已通过在 config/schedule.rb 文件中明确设置捆绑路径来解决。

    set :bundle_command, "/usr/local/bin/bundle exec" 
    

    这会在 cron 中创建条目,例如:

    30 1 * * * /bin/bash -l -c 'cd <app_path> && RAILS_ENV=beta /usr/local/bin/bundle exec rake 'task_name' --silent >> log/cron.log 2>&1'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-29
      • 2015-10-29
      • 1970-01-01
      • 2014-05-27
      相关资源
      最近更新 更多