TurnKey Linux Virtual Appliance Library

Cron in Magento supposed to be working by Default.. ?

L. Arnold's picture

I am being told that Cron is not operating in Magento.  Does anyone know the process in TKL to see if it is or is not, and moreover to be sure it is working for Magento as well as the system.

thanks for any and all help.

Jeremy's picture

Cron is enabled by default

That's what is used to install the security updates. But I'm not sure about Magento specific cron jobs as I don't use the Magento appliance.

There is a Webmin page that allows you to see what cron jobs are queued and their frequency etc. One anomaly with cron though, is that you either need to load environmental variables, or use the full path to scripts you wish to run from cron.

If there are Magento cron jobs that you think should be runnign by default in the Magento appliance which aren't in TKL Magento, then perhaps you could suggest them via a blueprint or a bug report (depending on how important/required you think they are). Then hopefully they'll be setup by default in the next TKL appliance. Even if they're not super important, if you think they are useful enough, even if the TKL devs don't have them enabled by default, the cron jobs themselves could be included but disabled (so end users can easily enable them).

Enabling Magento Cron Jobs

For the Magento internal cron jobs to run, you must set up a cron job that calls cron.sh in your Magento Root folder every 5 minutes (or whatever your web host's minimum time between recurrant cron jobs is. Cron Job Monitor php script

L. Arnold's picture

Just Added a new Cron job in Webmin

Not sure if this should run as User  "root" or "www-data"

also: What does the Magento Cron job that is set up by default do?

Now to check to see if it is running.  Must be some sort of a toggle test or something.

Thanks for the note on this.

Enabling Magento Cron Jobs

cron.sh needs to run as the Magento user (ssh login name) or www-data (depending on how your security is set up). You definitely don't want root as this could produce files unreadable by the web server. I've had Magento cache entries created by external scripts run as root. Definite show stopper.

What most people new to Magento don't know. No Magento cron jobs will run automatically. You can make all sorts of Magento System Config settings, change xml cron entries, etc to your never ending exasperation and no cron jobs will ever run. This is because cron.sh serves as a external trigger to wake the Magento web application up and have it run its cron job processes.

Fire cron.sh as the fuse and it sets off the chain reaction that is Magento cron.

Jeremy's picture

So Magento has it's own internal cron jobs?

So you would enable the system cron to run magento/cron.sh (as www-data) and then from within Magento you configure which jobs run?

@larnold - If that's the case then you could add the system cron job (ie to run /magento/cron.sh) from Webmin. And perhaps that should be the TKL OOTB default setup?

Magento Cron Jobs

Aside from the cron settings in System -> Configuration ->Advanced System, everything is pretty much already set up through the various module config.xml crontab sections.

Listing of various internal cron jobs set up in Magento 1.4.x.x
http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job#section1

L. Arnold's picture

Exploring Magento Cron some more... not getting too far.

I just turned on cron logs in Webmin, so that may help.

I have tried to create a manual cron job in Webmin and Magento is not allowing it.

It could be that there are ohter controls in the TKL magento cron file:

#!/bin/bash

/usr/bin/php /var/www/magento/cron.php > /dev/null 2>&1

Not sure why bin/bash is there.  It also appears to be commented out.  If I run the last line as its own command manually I get in webmin:

No output generated

Nothing shows up in the cron log (accessible via webmin)..

I may get the following in my Apache Error log, but the time seems out of kilter:  perhaps London time.

[Thu Dec 01 23:17:44 2011] [error] [client 10.10.10.163] client denied by server configuration: /var/www/magento/app/etc/local.xml

(perhaps local.xml is wanting the DNS to match and the above is the DMZ address not the Domain IP itself...  would seem strange, but perhaps)..  let me see if DNS rewrites are happening.

If I try to run cron.sh directly from the Browser I get it wanting to download...  and if I go open it it is reading like this:

#!/bin/sh
# location of the php binary
if [ ! "$1" = "" ] ; then
CRONSCRIPT=$1
else
CRONSCRIPT=cron.php
fi

PHP_BIN=`which php`

# absolute path to magento installation
INSTALLDIR=`echo $0 | sed 's/cron\.sh//g'`

#    prepend the intallation path if not given an absolute path
if [ "$INSTALLDIR" != "" -a "`expr index $CRONSCRIPT /`" != "1" ];then
    if ! ps auxwww | grep "$INSTALLDIR""$CRONSCRIPT" | grep -v grep 1>/dev/null 2>/dev/null ; then
    $PHP_BIN "$INSTALLDIR""$CRONSCRIPT" &
    fi
else
    if  ! ps auxwww | grep " $CRONSCRIPT" | grep -v grep | grep -v cron.sh 1>/dev/null 2>/dev/null ; then
        $PHP_BIN $CRONSCRIPT &
    fi
fi

If I run Magento's cron.php from the browser I don't see anything in the log, on the screen or anywhere.  It does appear to take some time and "do something", but again, no apache or cron logs.  I will look for some Magento cron logs...

This all feels like TKL is handling cron ok, but not so sure about Magento.  Perhaps Magento has its own Cron, and TKL has another and they are/or are not getting along.

thoughts on this one?

Jeremy's picture

I have no idea with Magento at all, but a few things...

The "#!/bin/bash" is known as a shebang and it is basically tells the script which shell to run (in this case it's bash).

The "> /dev/null 2>&1" basically makes the command run quietly. Generally you want cron jobs to run silently. Have a look here. I'm guessing that's why it says "no output generated".

From what I could gather from Sean's previous posts is that you need to setup the system cron to run the Magento cron script every 5 mins, then you adjust what jobs it actually does from within Magento itself. So basically the system cron that triggers the Magento cron.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)