Rails3,从 cron 运行 rake 任务

发布于 2024-10-29 09:28:53 字数 1131 浏览 1 评论 0原文

我从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

去了角落 2024-11-05 09:28:53

我想出了解决方法 - 从源代码安装 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

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

bundle install

以更新 Gemfile.lock

之后,我的脚本从 cron 运行。

I came up with workaround - installing rails-settings from source

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

and you have to remove ":git =>" from gem "rails-settings" in Gemfile, and run

bundle install

to update Gemfile.lock

After that my script run from cron.

姜生凉生 2024-11-05 09:28:53

为了避免构建 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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文