0

i deployed (with capistrano) a ruby on rails project on an aws micro server. I'm on ruby 1.9.2-290 and rails 3.2.6 and i also use bundler. I developed a task rake in my opt/rails-project/lib/tasks/tasks.rake

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

This is how i call it in my 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

The file ~/logs-my-task.txt is created and updated every 3min as it does. This file only contains info of the version release from capistrano but nothing from my task rake.

As i said in my comment in my task rake, if i launch this command directly in the server via ssh, my task rake does its job...

I searched the web all day/night long and can not figure it out.

I tried to remove the http_basic auth from rails but same problem.

Hope you have a idea, Thanks for help !

mfalla
  • 1
  • 1

2 Answers2

0

Try to put this part

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

inside some file, somescript.sh, give execution permissions:

chmod +x somescript.sh

and try to run it manually:

/path/to/somescript.sh

If it works, try to put it into crontab:

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

It often helps to put complex stuff inside script to run in from crontab.

Next step, ensure that you PATH environment variable the same for your shell and for cron. You can set it inside crontab or inside your script.

denis.peplin
  • 9,585
  • 3
  • 48
  • 55
  • Thanks ! I didn't need to use a sheel script but it helps me figure it out when i launched it manually. – mfalla Aug 02 '12 at 17:46
0

After I used a shell script as recommended by denis.peplin and launched it manually, I got the problem described here: Ruby on Rails and Rake problems: uninitialized constant Rake::DSL.

I included the following line in my Rakefile and let my crontab as it was before:

require 'rake/dsl_definition'
Community
  • 1
  • 1
mfalla
  • 1
  • 1