Showing results for 
Search instead for 
Did you mean: 

Disable Cronjobs when maintenance.flag is set?

Disable Cronjobs when maintenance.flag is set?


 I'm wondering if I should be disabling the calls to when the website is in maintenance mode?   Is this beneficial?


What I have being tested right now is shown below.  I added a new flag file called "cronstop.flag"  when present (in the install root) the script just exits without doing anything.   This lets me keep cron off even if the system cleared the maintenance.flag until I know things are stable.. 




# Magento
# This source file is subject to the Open Software License (OSL 3.0)
# that is bundled with this package in the file LICENSE.txt.
# It is also available through the world-wide-web at this URL:
# If you did not receive a copy of the license and are unable to
# obtain it through the world-wide-web, please send an email
# to so we can send you a copy immediately.
# Do not edit or add to this file if you wish to upgrade Magento to newer
# versions in the future. If you wish to customize Magento for your
# needs please refer to for more information.
# @category    Mage
# @package     Mage
# @copyright  Copyright (c) 2006-2015 X.commerce, Inc. (
# @license  Open Software License (OSL 3.0)

# location of the php binary
if [ ! "$1" = "" ] ; then

if [ ! "$2" = "" ] ; then
    MODE=" $2"

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 [ ! -f $INSTALLDIR$MAINTFLAG ]; then
    if ! ps auxwww | grep "$INSTALLDIR$CRONSCRIPT$MODE" | grep -v grep 1>/dev/null 2>/dev/null ; then
    if  ! ps auxwww | grep "$CRONSCRIPT$MODE" | grep -v grep | grep -v 1>/dev/null 2>/dev/null ; then


Any input is appreciated.




Re: Disable Cronjobs when maintenance.flag is set?

Yes, you should disable Magento cron jobs running when you are in maintenance mode.


Having cron run mid upgrade can create the very issues most people encounter and complain about crashing their installations when upgrading by running installer scripts in dribs and drabs as code uploads instead of one sequenced batch. The worst is when it gets down through part of the installer scripts for one of the modules, halts, attempts to restart and then FAILS on table already exists because it failed to upgrade the resource entries.


The KISS method is to create the following crontab entry (ymmv, /etc/crontab needs the addition of the "run as user column")


*/5 * * * *   ! test -e /path/to/magento/root/maintenance.flag && /bin/sh /path/to/magento/root/

with /path/to/magento/root/ being replaced with your specific path to the directory that Magento lives in.


It tests for the presence of maintenance.flag and if not exist, then runs


My upgrade and module install issues pretty much disappeared when I started to religiously shut off cron, shut off and clear the compiler and shut off and clear the Magento cache before doing these operations. Same goes for a database drop and reload, you don't have Magento interfering with MySQL during the database restore operation.