Rake not working when called through cron

This is currently the contents of “app-backup” in my cron.daily.


#!/bin/sh

Cron Job for Mixbook Code Backup

Updated February 1, 2007

cd /var/rails/beta
rake s3:backup:scm --trace >> /var/rails/beta/log/backup.log
cd /var/rails/beta/log
echo “Backup Successful on” >> backup.log
date >> backup.log
echo “–” >> backup.log

When I run the file “./app-backup,” the RAKE works fine and completes
successfully. However, when this same file is called through crontab, I
get the following output:


(in /var/rails/beta)
rake aborted!
Don’t know how to build task ‘s3:backup:scm’

(See full trace by running task with --trace)
Backup Successful on
Sat Apr 21 04:02:39 PDT 2007

Anybody have any clue why this is happening?

When I run the file “./app-backup,” the RAKE works fine and completes
successfully. However, when this same file is called through crontab, I
get the following output:


(in /var/rails/beta)
rake aborted!
Don’t know how to build task 's3:backup:scm

Are you sure you don’t have a file permission or path problem?

Stephan

hmm, doesnt the cron job work as Root? The thing is, if I got a
permissions problem, it would say that it couldnt even run the file in
the first place, but its clearly calling the Rake command.

I definately doubt its a path problem because I can run that same file
manually just fine.

Stephan W. wrote:

When I run the file “./app-backup,” the RAKE works fine and completes
successfully. However, when this same file is called through crontab, I
get the following output:


(in /var/rails/beta)
rake aborted!
Don’t know how to build task 's3:backup:scm

Are you sure you don’t have a file permission or path problem?

Stephan

On 4/24/07, Aryk G. [email protected] wrote:

hmm, doesnt the cron job work as Root? The thing is, if I got a
permissions problem, it would say that it couldnt even run the file in
the first place, but its clearly calling the Rake command.

Each user owns his/her crontab. Another possibility might have to do
with your environment settings, though. Have you tried putting what
you’ve got in your shell profile in the crontab?

d.

I believe Im running all this under root. I think I narrowed down the
problem a little though. When I run rake -T, I get a list of all the
available rake commands. The one i need to run isnt in there. It is only
in there when Im logged in.

This has something to do with the fact that the *.rake file is ran from
the vendors directory. It is ran from a plugin under the /tasks folder.
For some reason, when run from cron, it doesnt check the rake tasks from
the Rails plugins.

Any idea why?

I looked in the .profile and bashrc and there is nothing there that I
think could affect this. Where else should I look?

Lukhnos D. Liu wrote:

On 4/24/07, Aryk G. [email protected] wrote:

hmm, doesnt the cron job work as Root? The thing is, if I got a
permissions problem, it would say that it couldnt even run the file in
the first place, but its clearly calling the Rake command.

Each user owns his/her crontab. Another possibility might have to do
with your environment settings, though. Have you tried putting what
you’ve got in your shell profile in the crontab?

d.

It turns out that this issue is related to one line in the s3.rake file.
It actually is getting found, but the problem is, that there is an error
thrown, and rather than telling me, it says it cannot find the task.

Here is whats happening:

There is a line at the top- “require File.join(File.dirname(FILE),
‘…’)+’/lib/s3’”

Through testing, I found out that this is the problem line. I believe in
the original code it was requir ‘s3’. I changed it to what it is now
because it couldnt find the file before.

I checked the global variable &: for the lib directory and it is
include, I just don’t understand why it cant find it. That would solve
my problem. For some reason, when calling Rake from cron, it doesnt like
the File.join or File.dirname command.

Ok, I think I pin pointed this thing down a little more.

Its not the File command as I thought. It is calling s3.rb.

In that file, there are requirements that dont work when called from
cron.

All of these required rbs are not found or throw an error when run
through cron.

require ‘openssl’
require ‘digest/sha1’
require ‘net/https’

Do you guys have any idea why these required libraries would throw
errors only when Rake is called through cron?

Some thoughts on environment variables not available in cron:

http://kb.mediatemple.net/article.php?id=251

I’ve looked at that. While the RUBYLIB declaration definately helped, I
was running into a problem within the rake code. I think the popen
command was giving me problems through cron. It was trying to run “svn
info”. Have you guys ever heard of this problem?

Dr Nic wrote:

Some thoughts on environment variables not available in cron:

http://kb.mediatemple.net/article.php?id=251