I’ve one rake task which i want to execute once every day:
in production installed rvm
in schedule.rb i have
set :output, "/home/username/data/public_html/log/cron_log.log"
every 24.hours do
rake "fetch:smth"
end
crontab -l shows me:
MAILTO="my.mail@gmail.com"
PATH="/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby "
@daily cd /home/username/data/www/nameofsite.com && RAILS_ENV=production bundle exec rake fetch:smth
truly, i’m a little bit confused, coz previously i didn’t have experience with cron, so plz help.
EDIT #1
i’ve run rvm env — path 1.9.3@global
and it gave me:
PATH="/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:$PATH"
and then i’ve
MAILTO="said.kaldybaev@gmail.com"
PATH="/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:$PATH"
@daily RAILS_ENV=production rake rate:fetch
and when i run execute, from ISPmanager, it gave me: Exited with return code = 1
the link below says that if the exit error is 1, then there is already a /var/run/cron.pid file. and it’s true, but i don’t have root privileges
You don’t need
schedule.rbif you’re calling the task from cron. That’s handled by the@dailyentry in crontab. Just set the logfile name as an environment variable and have the rake task refer to that. You’ll probably also need more in your$PATHthan just the path to the ruby binary, otherwisebundleisn’t going to be found. While you’re giving the path to a ruby, you’re not actually selecting it for RVM to know what you mean, so it’s not going to be able to find the right gemset. RVM provides wrappers which Do The Right Thing for this sort of task – replacebundle execwith/usr/local/rvm/wrappers/ruby-1.9.3-p125 -S bundle execand it should work.Hope that gives you some ideas. There’s more here.
UPDATE #1
With Edit #1, you’ve fixed one problem and created another. You still need to
cdto the app directory, otherwise rake won’t find the Rakefile.