我试图设置运行rake任务的cron作业。每当我使用宝石。这里是Cron运行rake任务“无法在任何源中找到rake-0.8.7”
every 1.minutes do
bundle exec rake "test:pick_participant"
end
crontab中无论何时,只要正确设置在配置/ schedule.rb配置:
* * * * * /bin/bash -l -c 'cd /home/jsmith/webapp/releases/20111104200246 && RAILS_ENV=production bundle exec rake test:pick_participant --silent'
然而,克龙不断报告(通过电子邮件)这个错误每次工作是跑:
From: [email protected] (Cron Daemon)
To: [email protected]
Subject: Cron <[email protected]> /bin/bash -l -c 'cd /home/jsmith/webapp/releases/20111104200246 && RAILS_ENV=production bundle exec rake test:pick_participant --silent'
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <[email protected]>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/jsmith>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=jsmith>
Message-Id: <[email protected]>
Date: Mon, 7 Nov 2011 16:26:01 -0800 (PST)
expr: syntax error
Could not find rake-0.8.7 in any of the sources
捆绑在应用程序环境中的rake版本是0.8.7。
由cron发出的命令似乎是正确的:
/bin/bash -l -c 'cd /home/jsmith/webapp/releases/2067320376 && RAILS_ENV=production bundle exec rake test:pick_participant --silent'
它直接调用bundle exec rake
代替rake
。
另外,如果我在发布的应用程序目录中的命令行相同的命令,rake任务运行成功:
[email protected]:~/webapp/current$ /bin/bash -l -c 'cd /home/jsmith/webapp/releases/20111104200246 && RAILS_ENV=production bundle exec rake test:pick_participant --silent'
* picked participant: Mindy!
任何人有,为什么cron是遇到了此问题的任何想法“找不到耙0.8.7" ?
感谢您在crontab中提及'/ bin/bash -l -c'。这也解决了我与捆绑商的问题。 – Roman
很棒的回答。感谢您分享您的解决方案。 –