0

I am using the whenever gem to configure my crontab and schedule cron jobs. my config/schedule.rb file has the following content:

set :environment, "test"
set :output, {:error => "/var/log/cron_error.log", :standard => "/var/log/cron_log.log"}

every 1.minutes do
   runner 'TickerSymbol.update_prices'
end

At the moment I am invoking Rails.logger.debug ... in the TickerSymbol.update_prices method. Also, notice in the schedule.rb file that I am trying to write the output from the scheduled cron job to /var/logs/*.log. This is not working. When I view the logs on S3 or via the Beanstalk management console I see other log files from the /var/log directory, but I do not see my cron log files.

My .ebextensions/[app name].config file has the following content:

sources: 
  /aws-scripts-mon: http://ec2-downloads.s3.amazonaws.com/cloudwatch-samples/CloudWatchMonitoringScripts.zip

option_settings:
  - option_name: AWS_SECRET_KEY
    value: XXX
  - option_name: AWS_ACCESS_KEY_ID
    value: XXX
  - option_name: BUNDLE_WITHOUT
    value: "production:development"
  - option_name: RACK_ENV
    value: test
  - option_name: RAILS_ENV
    value: test
  - option_name: RAILS_SKIP_MIGRATIONS
    value: true

container_commands:
  01-setupcron:
    command: echo "*/5 * * * * root perl /aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail --aws-access-key-id $AWS_ACCESS_KEY_ID --aws-secret-key $AWS_SECRET_KEY > /dev/null" > /etc/cron.d/cwpump
  02-changeperm:
    command: chmod 644 /etc/cron.d/cwpump
  03-changeperm:
    command: chmod u+x /aws-scripts-mon/mon-put-instance-data.pl
  04-rake_routes:
    command: rake routes
  05-whenever:
    command: whenever -c
    command: whenever -i [app name] --update-crontab
    command: whenever -f
    command: crontab -l
    leader_only: true

Following is the content from my log file which is generated during my deployment with git aws.push. This log entry confirms that whenever is generating the crontab file as expected.

2013-04-06 14:50:37,469 [DEBUG] Running command 05-whenever
2013-04-06 14:50:37,470 [DEBUG] Generating defaults for command 05-whenever
<<<

2013-04-06 14:50:37,639 [DEBUG] Running test for command 05-whenever
2013-04-06 14:50:37,654 [DEBUG] Test command output: 
2013-04-06 14:50:37,654 [DEBUG] Test for command 05-whenever passed
2013-04-06 14:50:37,671 [INFO] Command 05-whenever succeeded
2013-04-06 14:50:37,671 [DEBUG] Command 05-whenever output: # Begin Whenever generated tasks for: [app name]
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /var/app/ondeck && script/rails runner -e production '\''TickerSymbol.update_prices'\'' >> /path/to/my/cron_log.log 2>&1'


# End Whenever generated tasks for: [app name]

Am I missing something? Based on the current configuration, I expect to see my log messages from TickerSymbol.update_prices inside my /var/log/cron_log.log file. However, I dont see any indication that these settings are producing an error nor do I see any indication that the cron job is running.

Athens Holloway
  • 2,183
  • 3
  • 17
  • 26

1 Answers1

0

Have a look at the output in the last log:

... cd /var/app/ondeck ...

This directory exists only during the deployment. If your crontab is setup to CD to it like it says, it won't work.

alg
  • 96
  • 5