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" 

有人知道怎么修这个东西吗?

我提出了解决方法 – 从源代码安装rails-settings

 wget https://github.com/100hz/rails-settings/zipball/master --no-check-certificate unzip 100hz-rails-settings-v0.1.1-0-g330b958.zip cd 100hz-rails-settings-330b958/ gem build rails-settings.gemspec gem install rails-settings-0.1.1.gem 

你必须从Gemfile中的gem“rails-settings”中删除“:git =>”,然后运行

 bundle install 

更新Gemfile.lock

之后我的脚本从cron运行。

为了避免构建gem,另一个选择是将gem内容放在vendor文件夹中并通过以下方式引用它:Gemfile中的path:

gem "my_gem", :path => "vendor/my_gem"