0

我在 aws 微服务器上部署了(使用 capistrano)一个 ruby​​ on rails 项目。我在 ruby​​ 1.9.2-290 和 rails 3.2.6 上,我也使用 bundler。我在我的 opt/rails-project/lib/tasks/tasks.rake 中开发了一个任务 rake

namespace :myclass do
    task "my-task" => :environment do
        # do the stuff which work nicely if i enter my command line manually
    end
end

这就是我在 crontab 中的称呼:

*/3 * * * * cd /opt/rails-project/current && /opt/rails-project/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake myclass:my-task RAILS_ENV=production >> ~/logs-my-task.txt

文件 ~/logs-my-task.txt 每 3 分钟创建和更新一次。该文件仅包含 capistrano 的版本发布信息,但没有来自我的任务 rake。

正如我在我的任务 rake 的评论中所说,如果我通过 ssh 直接在服务器中启动此命令,我的任务 rake 就完成了它的工作......

我整天/晚上都在网上搜索,但无法弄清楚。

我试图从 rails 中删除 http_basic auth 但同样的问题。

希望你有想法,谢谢帮助!

4

2 回答 2

0

试着把这部分

cd /opt/rails-project/current && /opt/rails-project/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake myclass:my-task RAILS_ENV=production >> ~/logs-my-task.txt

在某个文件中somescript.sh,授予执行权限:

chmod +x somescript.sh

并尝试手动运行它:

/path/to/somescript.sh

如果可行,请尝试将其放入 crontab 中:

*/3 * * * * /path/to/somescript.sh

将复杂的东西放入脚本中以从 crontab 运行通常会有所帮助。

下一步,确保您的 shell 和 cron 的 PATH 环境变量相同。您可以在 crontab 或脚本中设置它。

于 2012-08-02T06:27:25.250 回答
0

在我使用了推荐的 shell 脚本denis.peplin并手动启动它之后,我遇到了这里描述的问题:Ruby on Rails 和 Rake 问题:未初始化的常量 Rake::DSL

我在我的 Rakefile 中包含以下行,并让我的 crontab 和以前一样:

require 'rake/dsl_definition'
于 2012-08-02T17:53:47.153 回答