Rails3,如何从cron中运行rake任务

3

我在从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"

有人知道如何修复这个问题吗?

(涉及IT技术,具体问题不详)
2个回答

0
我找到了一个解决方法 - 从源代码中安装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中将"rails-settings"的":git =>"移除,并运行

bundle install

更新Gemfile.lock

之后我的脚本从cron运行。


0
为了避免构建一个 gem,另一个选项是将 gem 内容放在 vendor 文件夹中,并通过 Gemfile 中的 :path 引用它: gem "my_gem", :path => "vendor/my_gem"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接