【问题标题】:Whenever CRON tab doesn't work on Amazon EC2每当 CRON 选项卡在 Amazon EC2 上不起作用时
【发布时间】:2013-10-06 08:09:09
【问题描述】:

我正在尝试使用 Whenever gem 在 Amazon EC2 上设置 CRON 作业。 在schedule.rb 中如下:

 set :output, "/home/my_deploy_name/my_deploy_name/current/log/cron_log.log"

 every 2.minutes do
   puts "It's working !!!"
 end

deploy.rb这个:

...
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
after 'deploy:create_symlink', 'whenever:update_crontab'
after 'deploy:rollback', 'whenever:update_crontab'

当我将此代码部署到 EC2 并检查 crontab -l 时,输出为:

no crontab for ubuntu

当我运行crontab -e 时,文件没有被编辑。

这里有什么问题?什么 CRON 作业不是在 EC2 上每 2 分钟运行一次?

【问题讨论】:

    标签: ruby-on-rails ruby amazon-ec2 cron whenever


    【解决方案1】:

    一些可以尝试的选项:

    1) 登录服务器并运行:

    bundle exec whenever --update-crontab

    并检查您的 crontab。

    2) 您不需要设置 beforeafter 回调。 capistrano 食谱可以为您做到这一点:

    https://github.com/javan/whenever/blob/master/lib/whenever/capistrano.rb

    Capistrano::Configuration.instance(:must_exist).load do
      # Write the new cron jobs near the end.
      before "deploy:finalize_update", "whenever:update_crontab"
      # If anything goes wrong, undo.
      after "deploy:rollback", "whenever:update_crontab"
    end
    

    【讨论】:

    • 我正在使用gem 'whenever', :require => false,也更新了那里的recipes,但仍然没有ubuntu 的crontab
    • 你使用的是什么版本的whenever
    • 我的意思是,当我使用 capistrano 将代码部署到 EC2 时,cron 作业应该自动在 EC2 本身上运行?是不是需要激活呢?在本地主机上,我看到 crontab -l 的输出,但在 EC2 上看不到。
    • 最后一个 - 0.8.4
    • 更新了我的答案。您应该尝试手动操作。您可能会遇到错误,并且只能在登录到您的 EC2 实例时看到。
    猜你喜欢
    • 2013-10-06
    • 2018-02-21
    • 2014-06-30
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 2012-05-15
    • 1970-01-01
    • 2013-11-21
    相关资源
    最近更新 更多