User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 
I have been asked a few times how to get RakeFile working with cron on Ubuntu v10-12.
You will need to make your .sh script work from command line first.
This is just to help you getting it to work with cron

First make your .sh script.
Get your full path first.
$ echo $PATH
now copy that path down because you will want it for your script.
In the below script change PATH= to whatever your path was from above $ nano runrakes.sh

#!/usr/bin/env ruby
PATH=/usr/local/rvm/gems/ruby-1.9.3-p429/bin:/usr/local/rvm/gems/ruby-1.9.3-p429@global/bin....etc....
cd /var/www/vhosts/redmine
/usr/local/rvm/gems/ruby-1.9.3-p429/bin/rake -f /var/www/vhosts/redmine/Rakefile redmine:email:receive_pop3 RAILS_ENV="production" host=10.10.1.55 username=emailpopusername password=mypassword




now make a cron task for the web user. This is set to run every 5 minutes. If you have a lot of email traffic you may want to make it something closer to 30 minutes.
crontab -e -u www-data
*/5 * * * * /var/www/vhosts/redmine/runrakes.sh


Now your emails or script for rake should run.

If you run into issues after the security updates. you can do this:
$ env
copy all the vars
with the exception of any that fail when you try to run it via command line for testing.
remove: #!/usr/bin/env ruby
paste all the vars there

$ nano runrakes.sh


rvm_bin_path=/usr/local/rvm/bin
GEM_HOME=/usr/local/rvm/gems/ruby-1.9.3-p429
TERM=xterm
SHELL=/bin/bash
IRBRC=/usr/local/rvm/rubies/ruby-1.9.3-p429/.irbrc
OLDPWD=/var/www/vhosts/redmine
MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-1.9.3-p429
SSH_TTY=/dev/pts/0
USER=root
rvm_path=/usr/local/rvm
rvm_prefix=/usr/local
MAIL=/var/mail/root
PATH=/usr/local/rvm/gems/ruby-1.9.3-p429/bin:etc......
PWD=/usr/bin
LANG=en_US.UTF-8
SHLVL=1
HOME=/root
LOGNAME=root
GEM_PATH=/usr/local/rvm/gems/ruby-1.9.3-p429:/usr/local/rvm/gems/ruby-1.9.3-p429@global
RUBY_VERSION=ruby-1.9.3-p429
cd /var/www/vhosts/redmine
/usr/local/rvm/gems/ruby-1.9.3-p429/bin/rake -f /var/www/vhosts/redmine/Rakefile redmine:email:receive_pop3 RAILS_ENV="production" host=10.10.1.55 username=emailpopusername password=mypassword