Rake not found

Added by Jasen Burkett over 2 years ago

I can run the rake command to import email from server outside of cron (directly in the terminal). I do cd into the directory where redmine is (/usr/share/redmine/) and it works like a charm.

However, as soon as I put the same rake command into a cronjob, it says it can not find the rake file... but the format is the same... the only change is the time i have it running... i.e. 0 * * * * rake....

Anyway. I am not sure where to look for solution / help on this so I am hoping you all could help me out on this please.

Thank you in adv.

Replies (7)

RE: Rake not found - Added by Martin Denizet (redmine.org team member) over 2 years ago

Hello Jasen,

Here is how I do it:
I create a .sh file with content as following:

#!/bin/sh
export GEM_HOME=/usr/local/rvm/gems/ruby-2.1.3
export PATH=/usr/local/rvm/gems/ruby-2.1.3/bin:/usr/local/rvm/gems/ruby-2.1.3@global/bin:/usr/local/rvm/rubies/ruby-2.1.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/rvm/bin
export GEM_PATH=/usr/local/rvm/gems/ruby-2.1.3:/usr/local/rvm/gems/ruby-2.1.3@global
export IRBRC=/usr/local/rvm/rubies/ruby-2.1.3/.irbrc
export MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-2.1.3
cd /opt/redmine/current && RAILS_ENV=production bundle exec rake SOMECOMMAND HERE >> /tmp/SOMETMPLOG.log

I create it doing (from memory, no guarantee you can just copy/paste):

echo '#!/bin/sh' > /opt/redmine-crontab.sh
echo "export PATH=$PATH" >> /opt/redmine-crontab.sh
echo "export GEM_PATH=$GEM_PATH" >> /opt/redmine-crontab.sh
echo "export IRBRC=$IRBRC" >> /opt/redmine-crontab.sh
echo "export MY_RUBY_HOME=$MY_RUBY_HOME" >> /opt/redmine-crontab.sh
echo 'cd /opt/redmine/current && RAILS_ENV=production bundle exec rake SOMECOMMAND HERE >> /tmp/SOMETMPLOG.log' >> /opt/redmine-crontab.sh

Then I execute this script file from the crontab. Mind write permission not to allow anyone to alter your script.
To adapt according to your needs.

Cheers,

RE: Rake not found - Added by Jasen Burkett over 2 years ago

does it matter that this all worked from cron before I did the database import from an older version of redmine.

I had tons of problems because of the draastic version difference, but have since worked out the issues of course. Then this... which is why I am so confused because the db doesnt have anything to do with the rake command does it??

Thanks by the way for your response, and QUICK response at that! I appreciate it.

RE: Rake not found - Added by Jasen Burkett over 2 years ago

Also, here is the exact error from the error file...

/bin/sh: 1: rake: not found

RE: Rake not found - Added by Tuan Phan Anh 7 months ago

Hi all,
Did you found the way out on this. I am facing the same issue now.

RE: Rake not found - Added by Martin Denizet (redmine.org team member) 7 months ago

Did you try using something like:

RAILS_ENV=production bundle exec rake

RE: Rake not found - Added by Tuan Phan Anh 6 months ago

Yes, I have tried.

My rake task like this:

*/01 * * * * cd /var/www/redmine && /usr/local/bin/rake -f /var/www/redmine/Rakefile redmine:email:receive_imap RAILS_ENV=production host=mail.one.com.vn username=abc@foo.com password="123456" port=993 ssl=SSL priority=normal project=customer-support tracker=support allow_override=all unknown_user=accept no_permission_check=1 no_account_notice=0 move_on_success=Success move_on_failure=Failure

With this rake I received the following log:

From root@centos6.local  Tue Feb  7 21:01:01 2017
Return-Path: <root@centos6.local>
X-Original-To: root
Delivered-To: root@centos6.local
Received: by centos6.local (Postfix, from userid 0)
        id D5EE680BE6; Tue,  7 Feb 2017 21:01:01 +0700 (ICT)
From: root@centos6.local (Cron Daemon)
To: root@centos6.local
Subject: Cron <root@centos6> cd /var/www/redmine && /usr/local/bin/rake -f /var/www/redmine/Rakefile redmine:email:receive_imap RAILS_ENV=production host=mail.foo.com username=abc@foo.com password="123456" port=993 ssl=SSL priority=normal project=customer-support tracker=support allow_override=all unknown_user=accept no_permission_check=1 no_account_notice=0 move_on_success=Success move_on_failure=Failure
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <LANG=en_US.UTF-8>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: <20170207140101.D5EE680BE6@centos6.local>
Date: Tue,  7 Feb 2017 21:01:01 +0700 (ICT)

/usr/lib/ruby/site_ruby/1.8/rubygems.rb:323:in `bin_path': can't find gem rake (>= 0.a) (Gem::GemNotFoundException)
        from /usr/local/bin/rake:22

RE: Rake not found - Added by Tuan Phan Anh 6 months ago

When I tried "RAILS_ENV=production bundle exec rake" I received the below error log:

/bin/sh: bundle: command not found

(1-7/7)