Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cron and bundle exec problem

I've upgraded to rails 3.0.9 which has introduced the rake issues. I've gotten it all resolved except for a problem with a cron job.

This used to work:

#!/bin/sh
source /usr/local/rvm/scripts/rvm 
cd /home/p1r65759/apps/abbc/
/usr/local/bin/rake refresh_events RAILS_ENV=production

But now I get this error: You have already activated rake 0.8.7, but your Gemfile requires rake 0.9.2. Consider using bundle exec. /home/p1r65759/apps/abbc/Rakefile:4:in `' (See full trace by running task with --trace)

How do I modify my script to use bundle exec so it will use the proper version of rake and run successfully? Thanks.

like image 367
Brett Avatar asked Aug 17 '11 16:08

Brett


2 Answers

If you are using bundler for your application then you don't need to use "/usr/local/bin/rake" as a path for rake.

you can just use

bundle exec rake

so your new script will be

#!/bin/sh
source /usr/local/rvm/scripts/rvm 
cd /home/p1r65759/apps/abbc/
bundle exec rake refresh_events RAILS_ENV=production

bundle exec will work because you are already in your project directory.

And don't forgot to include rake in your Gemfile.

like image 52
arunagw Avatar answered Nov 15 '22 17:11

arunagw


instead of

/usr/local/bin/rake refresh_events RAILS_ENV=production

you should use

bundle exec rake refresh_events RAILS_ENV=production

or better yet install your bundle with --binstubs:

bundle install --binstubs --without development test

then you will have bin/rake:

./bin/rake refresh_events RAILS_ENV=production
like image 42
Vitaly Kushner Avatar answered Nov 15 '22 16:11

Vitaly Kushner