Rails3,从 cron 运行 rake 任务
我从 cron 运行 rake 任务时遇到问题,我将其包装在 shell 文件中,当我从控制台执行此 shell 文件时,它工作正常。
#!/bin/sh
if ps -ef | grep -v grep | grep create_all_accounts ; then
exit 0
else
cd /home/prosoftstudio/www/prosoftstudio_egabinet && /home/prosoftstudio/www/.ruby/gems/1.8/bin/rake gabinet:create_all_accounts RAILS_ENV=production --trace
exit 0
fi
crontab 中的条目看起来像这样(我设置了 PATH 和 GEM_PATH)
PATH=/home/prosoftstudio/www/.python/bin:/usr/local/python2.6/bin:/home/prosoftstudio/www/.ruby/gems/1.8/bin/:/usr/local/ruby1.8/bin:/usr/local/bin:/usr/bin:/bin:/us$
GEM_PATH=/home/prosoftstudio/www/.ruby/gems/1.8:/home/prosoftstudio/www/.ruby/gems/1.8/bundler/gems:/usr/lib/ruby/gems/1.8/
*/1 * * * * /home/prosoftstudio/www/cron_create_accounts.sh > cron_log.txt 2>&1
我得到的输出是
rake aborted!
git://github.com/100hz/rails-settings.git (at master) is not checked out. Please run `bundle install`
似乎找不到安装的 gem
gem "rails-settings", :git => "git://github.com/100hz/rails-settings.git"
有谁知道如何解决这个问题?
I'm having problems running my rake task from cron, I wrap it in shell file and when I execute this shell file from console it works fine.
#!/bin/sh
if ps -ef | grep -v grep | grep create_all_accounts ; then
exit 0
else
cd /home/prosoftstudio/www/prosoftstudio_egabinet && /home/prosoftstudio/www/.ruby/gems/1.8/bin/rake gabinet:create_all_accounts RAILS_ENV=production --trace
exit 0
fi
Entry in crontab looks like this(I set PATH and GEM_PATH)
PATH=/home/prosoftstudio/www/.python/bin:/usr/local/python2.6/bin:/home/prosoftstudio/www/.ruby/gems/1.8/bin/:/usr/local/ruby1.8/bin:/usr/local/bin:/usr/bin:/bin:/us$
GEM_PATH=/home/prosoftstudio/www/.ruby/gems/1.8:/home/prosoftstudio/www/.ruby/gems/1.8/bundler/gems:/usr/lib/ruby/gems/1.8/
*/1 * * * * /home/prosoftstudio/www/cron_create_accounts.sh > cron_log.txt 2>&1
The output I get is
rake aborted!
git://github.com/100hz/rails-settings.git (at master) is not checked out. Please run `bundle install`
It seems like it can't find gems installed with
gem "rails-settings", :git => "git://github.com/100hz/rails-settings.git"
Anyone know how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想出了解决方法 - 从源代码安装 Rails-settings
并且您必须删除“:git =>”从 Gemfile 中的 gem“rails-settings”,然后运行
以更新 Gemfile.lock
之后,我的脚本从 cron 运行。
I came up with workaround - installing rails-settings from source
and you have to remove ":git =>" from gem "rails-settings" in Gemfile, and run
to update Gemfile.lock
After that my script run from cron.
为了避免构建 gem,另一种选择是将 gem 内容放在供应商文件夹中,并通过 Gemfile 中的 :path 引用它:
gem "my_gem", :path => “供应商/my_gem”
To avoid building a gem, another option is to put the gem content in the vendor folder and reference it through :path in Gemfile:
gem "my_gem", :path => "vendor/my_gem"