简体   繁体   English

cron job在magento site工作 - 但没有发现心跳

[英]cron job is working in magento site- But No heartbeat found

for our magento site, suddenly cron job stopped working. 对于我们的magento网站,突然cron工作停止了工作。

when we are trying to set up cron job using below command, it give error as : 当我们尝试使用下面的命令设置cron作业时,它会给出错误:

-bash: */5: No such file or directory

command : 命令:

*/5 * * * * php -f /var/www/html/sitename/cron.php

Edit 编辑

we have 2 sites on the same server. 我们在同一台服务器上有2个站点。

we have a custom module to check if the cron is working or not. 我们有一个自定义模块来检查cron是否正常工作。

in one site we are getting the below message 在一个网站,我们收到以下消息

在此输入图像描述

in another site, this message: 在另一个网站,这条消息:

在此输入图像描述

在此输入图像描述

cron.php cron.php

<?php
/**
 * 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)
 */

// Change current directory to the directory of current script
chdir(dirname(__FILE__));


require 'app/Mage.php';

if (!Mage::isInstalled()) {
    echo "Application is not installed yet, please complete install wizard first.";
    exit;
}

// Only for urls
// Don't remove this
$_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
$_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);

Mage::app('admin')->setUseSessionInUrl(false);

umask(0);

$disabledFuncs = explode(',', ini_get('disable_functions'));
$isShellDisabled = is_array($disabledFuncs) ? in_array('shell_exec', $disabledFuncs) : true;
$isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;
$isShellDisabled = true;

try {
    if (stripos(PHP_OS, 'win') === false) {
        $options = getopt('m::');
        if (isset($options['m'])) {
            if ($options['m'] == 'always') {
                $cronMode = 'always';
            } elseif ($options['m'] == 'default') {
                $cronMode = 'default';
            } else {
                Mage::throwException('Unrecognized cron mode was defined');
            }
        } else if (!$isShellDisabled) {
            $fileName = basename(__FILE__);
            $baseDir = dirname(__FILE__);
            shell_exec("/bin/sh $baseDir/cron.sh $fileName -mdefault 1 > /dev/null 2>&1 &");
            shell_exec("/bin/sh $baseDir/cron.sh $fileName -malways 1 > /dev/null 2>&1 &");
            exit;
        }
    }

    Mage::getConfig()->init()->loadEventObservers('crontab');
    Mage::app()->addEventArea('crontab');
    if ($isShellDisabled) {
        Mage::dispatchEvent('always');
        Mage::dispatchEvent('default');
    } else {
        Mage::dispatchEvent($cronMode);
    }
} catch (Exception $e) {
    Mage::printException($e);
    exit(1);
}

?>

<?php
Mage::log('cron working', null, 'cron.log');
?>

when i add this code at the end of cron.php , and run the file in browser, it showed : Tuesday 17th of May 2016 07:12:03 PM so seems cron is running. 当我在cron.php的末尾添加此代码,并在浏览器中运行该文件时,它显示: Tuesday 17th of May 2016 07:12:03 PM似乎cron正在运行。 but why Heartbeat not found ? 为什么没有找到Heartbeat?

try {
   $myFile = "cronlog.txt";
   $fh = fopen($myFile, 'w');
   $stringData = date('l jS \of F Y h:i:s A');
   fwrite($fh, $stringData);
   fclose($fh);
} catch (Exception $e) {
   Mage::printException($e);
}

Edit 2 编辑2

in email we are getting these error : 在电子邮件中我们收到这些错误:

Cron error while executing searchsphinx_check_daemon: 执行searchsphinx_check_daemon时出现Cron错误:

exception 'Mage_Core_Exception' with message 'Too late for the schedule.' inapp/Mage.php:595
Stack trace:
#0app/code/community/Aoe/Scheduler/Model/Observer.php(47): Mage::throwException('Too late for th...')
#1app/code/core/Mage/Core/Model/App.php(1338): Aoe_Scheduler_Model_Observer->dispatch(Object(Varien_Event_Observer))
#2app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Aoe_Scheduler_Model_Observer), 'dispatch', Object(Varien_Event_Observer))
#3app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('default', Array)
#4cron.php(76): Mage::dispatchEvent('default')
#5 {main}

cron log cron日志

2016-05-24T12:30:02+00:00 DEBUG (7): Start: captcha_delete_old_attempts
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: captcha_delete_old_attempts
2016-05-24T12:30:02+00:00 DEBUG (7): Start: mstcore_logger_cron
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: mstcore_logger_cron
2016-05-24T12:30:02+00:00 DEBUG (7): Start: newsletter_send_all
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: newsletter_send_all
2016-05-24T12:30:02+00:00 DEBUG (7): Start: searchsphinx_check_daemon
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: searchsphinx_check_daemon
2016-05-24T12:30:02+00:00 DEBUG (7): Start: searchsphinx_reindex_delta_job
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: searchsphinx_reindex_delta_job
2016-05-24T12:30:02+00:00 DEBUG (7): Start: xmlconnect_notification_send_all
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: xmlconnect_notification_send_all
2016-05-24T12:30:03+00:00 DEBUG (7): Start: aoescheduler_heartbeat
2016-05-24T12:30:03+00:00 DEBUG (7): Stop: aoescheduler_heartbeat
2016-05-24T12:30:03+00:00 DEBUG (7): Start: captcha_delete_expired_images
2016-05-24T12:30:03+00:00 DEBUG (7): Job "captcha_delete_expired_images" (id: 133636) is locked. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Stop: captcha_delete_expired_images
2016-05-24T12:30:03+00:00 DEBUG (7): Start: captcha_delete_old_attempts
2016-05-24T12:30:03+00:00 DEBUG (7): Job "captcha_delete_old_attempts" (id: 133638) is locked. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Stop: captcha_delete_old_attempts
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:31" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:32" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:33" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "captcha_delete_expired_images" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "captcha_delete_expired_images" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Generated schedule. Newest task is scheduled at "2016-05-24 12:49:00". (Duration: 0.37 sec)
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:31" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:32" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:33" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:34" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:36" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:37" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:38" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:39" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:41" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:42" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:43" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:44" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:46" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:47" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:48" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:49" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_reindex_delta_job" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:31" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:32" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:33" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:34" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:36" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:37" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:38" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:39" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:41" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:42" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:43" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:44" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Generated schedule. Newest task is scheduled at "2016-05-24 12:49:00". (Duration: 0.21 sec)
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:46" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:47" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:48" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:49" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_reindex_delta_job" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Generated schedule. Newest task is scheduled at "2016-05-24 12:49:00". (Duration: 0.28 sec)
2016-05-24T12:31:02+00:00 DEBUG (7): Start: mstcore_logger_cron
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: mstcore_logger_cron
2016-05-24T12:31:02+00:00 DEBUG (7): Start: newsletter_send_all
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: newsletter_send_all
2016-05-24T12:31:02+00:00 DEBUG (7): Start: aoescheduler_heartbeat
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: aoescheduler_heartbeat
2016-05-24T12:31:02+00:00 DEBUG (7): Start: searchsphinx_reindex_delta_job
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: searchsphinx_reindex_delta_job
2016-05-24T12:31:02+00:00 DEBUG (7): Start: captcha_delete_expired_images
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: captcha_delete_expired_images
2016-05-24T12:31:02+00:00 DEBUG (7): Start: xmlconnect_notification_send_all
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: xmlconnect_notification_send_all
2016-05-24T12:31:02+00:00 DEBUG (7): Start: captcha_delete_old_attempts
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: captcha_delete_old_attempts
2016-05-24T12:31:02+00:00 DEBUG (7): Start: searchsphinx_check_daemon
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: searchsphinx_check_daemon
2016-05-24T12:32:02+00:00 DEBUG (7): Start: searchsphinx_check_daemon
2016-05-24T12:32:02+00:00 DEBUG (7): Stop: searchsphinx_check_daemon
*/5 * * * * date >> /var/www/html/magento/var/log/cron.log;/bin/sh -f /var/www/html/magento/cron.sh >> /var/www/html/magento/var/log/cron.log;

我们还运行我们的crontab作为apache用户,因为apache是​​我们所有magento文件的所有者:

sudo crontab -e -u apache

If you have two site on same server make sure you call cron.php for each site. 如果您在同一台服务器上有两个站点,请确保为每个站点调用cron.php。

Another reason why your cron is not running correctly it's you have job that take a time and another jobs doesn't start at all. 你的cron运行不正常的另一个原因是你的工作花了一些时间而另一个工作根本没有开始。

You can check status of cron jobs in db in table cron_schedule. 您可以在表cron_schedule中检查db中cron作业的状态。 In this table you can see details about each jobs, start and finish time and errors. 在此表中,您可以查看有关每个作业,开始和结束时间以及错误的详细信息。

Please check : https://gielberkers.com/solving-too-late-for-the-schedule-with-magento-crons/ 请检查: https//gielberkers.com/solving-too-late-for-the-schedule-with-magento-crons/

It will give you the possible options to check/validate the setting. 它将为您提供检查/验证设置的可能选项。

Also check the extension code for "date_default_timezone_set" word and see what value is given as default. 还要检查“date_default_timezone_set”字的扩展名,并查看默认值。 Is it the same as your magento store. 它和你的magento商店一样吗?

I guess you need two cron job setup in your server. 我想你的服务器需要两个cron作业设置。 Try to run another site's cron.php by giving its path. 尝试通过提供其路径来运行另一个站点的cron.php。

like 喜欢

*/5 * * * * php -f /var/www/html/sitename/cron.php 
*/5 * * * * php -f /var/www/html/sitename-2/cron.php

Also check for cron log 还要检查cron日志

sudo grep CRON /var/log/syslog

Executing this command you can see whether your cron is running or not. 执行此命令可以查看您的cron是否正在运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM