#Crontab runs this every ten minutes (root)
*/10 * * * * /root/scripts/redmine-rake.sh > /tmp/redmine-email.log 2>&1
#this is the script
One of the recent projects I gave myself was setting up redmine for project management. I’ve found it to be a great project management system and since I’ve been looking for alternatives to Basecamp-because of the monthly extortion fees-this one stood out. I’ll leave a review for another post but it’s the best tool I’ve found, much better than trac, and since I’m really familiar with it (Shane and Peter, whom I’ve been working a lot with lately, use the tool) it was an easy choice.
The choice may have been easy but the installation and parts of the setup were not.
One issue was getting a simple cron job to run the rake task of fetching email.
I was continually getting errors like:
/usr/bin/rake:9:in 'require': no such file to load -- rubygems (LoadError)
from /usr/bin/rake:9
Turns out when rake is run in cron, the .bash_profile file is not processed, so you must include the environment initialization in your cron script. I should have figured this out yesterday, instead I spent countless hours figuring this out.
Here is the cron I’m using:
#Crontab runs this every ten minutes (root)
*/10 * * * * /root/scripts/redmine-rake.sh > /tmp/redmine-email.log 2>&1
This is the bash script I’m using:
#!/bin/bash
export PATH=$PATH:/usr/local/rubygems/bin:/usr/local/rubygems/gems/bin
export RUBYLIB=/usr/local/rubygems/lib
export GEM_HOME=/usr/local/rubygems/gems
cd /var/www/vhosts/scatter3d.com/subdomains/redmine/httpdocs
RAILS_ENV="production" rake redmine:email:receive_imap port=993 host=imap.gmail.com username=redmine@domain.com password=redmine42 ssl=1
cd /var/www/[FULL PATH]/subdomains/redmine/httpdocs
RAILS_ENV="production" /usr/local/rubygems/gems/bin/rake redmine:email:receive_imap host=imap.gmail.com username=[username] password=[password] ssl=YES port=993
For those interested those settings are for gmail apps, so you’ll need to change them accordingly.