I'm wondering if I should be disabling the calls to Cron.sh 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 cron.sh 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..
(modified cron.sh)
#!/bin/sh
#
# Magento
#
# NOTICE OF LICENSE
#
# 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:
# http://opensource.org/licenses/osl-3.0.php
# 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 license@magento.com so we can send you a copy immediately.
#
# DISCLAIMER
#
# 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 http://www.magento.com for more information.
#
# @category Mage
# @package Mage
# @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
# @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
#
# location of the php binary
if [ ! "$1" = "" ] ; then
CRONSCRIPT=$1
else
CRONSCRIPT=cron.php
fi
MODE=""
if [ ! "$2" = "" ] ; then
MODE=" $2"
fi
PHP_BIN=`which php`
# absolute path to magento installation
INSTALLDIR=`echo $0 | sed 's/cron\.sh//g'`
MAINTFLAG=cronstop.flag
# 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
$PHP_BIN $INSTALLDIR$CRONSCRIPT$MODE &
fi
else
if ! ps auxwww | grep "$CRONSCRIPT$MODE" | grep -v grep | grep -v cron.sh 1>/dev/null 2>/dev/null ; then
$PHP_BIN $CRONSCRIPT$MODE &
fi
fi
fi
Any input is appreciated.
Eric
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/cron.sh
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 cron.sh
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.
I am using this script:
#!/bin/bash
BASE_DIR=`dirname "$(readlink -f "$0")"`
if [ -f "$BASE_DIR/.maintenance.flag" ] || [ -f "$BASE_DIR/.cron-off.flag" ]; then
exit
fi
## Magento standard crons
LOGFILE=$BASE_DIR/var/log/magento.cron.log
touch $LOGFILE
$BASE_DIR/bin/magento cron:run | grep -v "Ran jobs by schedule" >> $LOGFILE
$BASE_DIR/update/cron.php | grep -v "Ran jobs by schedule" >> $LOGFILE
$BASE_DIR/bin/magento setup:cron:run | grep -v "Ran jobs by schedule" >> $LOGFILE
#!/bin/bash
BASE_DIR=`dirname "$(readlink -f "$0")"`
if [ -f "$BASE_DIR/.maintenance.flag" ] || [ -f "$BASE_DIR/.cron-off.flag" ]; then
exit
fi
## Magento standard crons
LOGFILE=$BASE_DIR/var/log/magento.cron.log
touch $LOGFILE
$BASE_DIR/bin/magento cron:run | grep -v "Ran jobs by schedule" >> $LOGFILE
$BASE_DIR/bin/magento setup:cron:run | grep -v "Ran jobs by schedule" >> $LOGFILE
## SATA specifics
$BASE_DIR/bin/magento imi:push:batch-orders >> $BASE_DIR/var/log/cron-push.log