7

How do I make sure my Magento cron job is running? I setup cron per the Magento 2 installation instructions for the log files.

See screen shot (click to enlarge):

https://drive.google.com/open?id=0Bytqhoir_Tt5TG5LTWh5TmYxN28

I am running Magento CE 2.0.2

Server Platform:

  • Operating System: CENTOS 7.2 x86_64
  • CPU: Dual Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz
  • RAM: 256 GB
  • Storage: SSD Based Cloud Storage
  • Network: 20 Gigabits
  • Server UI: cPanel/WHM 54.0 Build 18 (latest/stable)
  • Apache: 2.2.26
  • MySQL: 5.6.29
  • PHP: 5.6.18

Crontab for the cPanel user host account:

*/1 * * * * /usr/local/bin/php -c /usr/local/lib/php.ini /home/abcdefg/public_html/bin/magento cron:run > /home/abcdefg/public_html/var/log/magento.cron.log&
*/1 * * * * /usr/local/bin/php -c /usr/local/lib/php.ini /home/abcdefg/public_html/update/cron.php > /home/abcdefg/public_html/var/log/update.cron.log&
*/1 * * * * /usr/local/bin/php -c /usr/local/lib/php.ini /home/abcdefg/public_html/bin/magento setup:cron:run > /home/abcdefg/public_html/var/log/setup.cron.log&

Added 2016-05-05

I was informed that the MySQL cron_schedule contains cron activity. So I looked at the table and found these entries. Here is a snippet of each of the unique entries in that table showing their latest entry.

55534 aggregate_sales_report_coupons_data running Class Magento\SalesRule\Crone\AggregateSalesReportCouponsData does not exist 2016-05-04 19:54:02 2016-05-04 20:00:00 NULL NULL
56093 captcha_delete_expired_images success NULL 2016-05-05 07:06:03 2016-05-05 07:10:00 2016-05-05 07:10:02 2016-05-05 07:10:02
56081 captcha_delete_old_attempts success NULL 2016-05-05 06:51:02 2016-05-05 07:00:00 2016-05-05 07:00:03 2016-05-05 07:00:03
56070 catalog_index_refresh_price success NULL 2016-05-05 06:51:02 2016-05-05 07:00:00 2016-05-05 07:00:03 2016-05-05 07:00:03
56094 magento_newrelicreporting_cron success NULL 2016-05-05 07:06:03 2016-05-05 07:06:00 2016-05-05 07:07:03 2016-05-05 07:07:03
56092 newsletter_send_all success NULL 2016-05-05 07:06:03 2016-05-05 07:10:00 2016-05-05 07:10:02 2016-05-05 07:10:02
56071 sales_clean_orders success NULL 2016-05-05 06:51:02 2016-05-05 07:00:00 2016-05-05 07:00:03 2016-05-05 07:00:03
56084 sales_grid_order_async_insert success NULL 2016-05-05 07:06:03 2016-05-05 07:06:00 2016-05-05 07:07:03 2016-05-05 07:07:03
56087 sales_grid_order_creditmemo_async_insert success NULL 2016-05-05 07:06:03 2016-05-05 07:06:00 2016-05-05 07:07:03 2016-05-05 07:07:03
56085 sales_grid_order_invoice_async_insert success NULL 2016-05-05 07:06:03 2016-05-05 07:06:00 2016-05-05 07:07:03 2016-05-05 07:07:03
56086 sales_grid_order_shipment_async_insert success NULL 2016-05-05 07:06:03 2016-05-05 07:06:00 2016-05-05 07:07:03 2016-05-05 07:07:03
56091 sales_send_order_creditmemo_emails success NULL 2016-05-05 07:06:03 2016-05-05 07:06:00 2016-05-05 07:07:03 2016-05-05 07:07:03
56088 sales_send_order_emails success NULL 2016-05-05 07:06:03 2016-05-05 07:06:00 2016-05-05 07:07:03 2016-05-05 07:07:03
56089 sales_send_order_invoice_emails success NULL 2016-05-05 07:06:03 2016-05-05 07:06:00 2016-05-05 07:07:03 2016-05-05 07:07:03
56090 sales_send_order_shipment_emails success NULL 2016-05-05 07:06:03 2016-05-05 07:06:00 2016-05-05 07:07:03 2016-05-05 07:07:03

Also, how can I get the 3 log file crons to run that I setup upon initial install:

*/1 * * * * /usr/local/bin/php -c /usr/local/lib/php.ini /home/abcdefg/public_html/bin/magento cron:run >> /home/abcdefg/public_html/var/log/magento.cron.log&
*/1 * * * * /usr/local/bin/php -c /usr/local/lib/php.ini /home/abcdefg/public_html/update/cron.php >> /home/abcdefg/public_html/var/log/update.cron.log&
*/1 * * * * /usr/local/bin/php -c /usr/local/lib/php.ini /home/abcdefg/public_html/bin/magento setup:cron:run >> /home/abcdefg/public_html/var/log/setup.cron.log&

Finally, I remember a few years back when I installed a Magento instance for a client in Magento v1 that somehow the pages index & cache and product index & cache got updated automatically through cron somehow. How can I get Magento 2 to do that same thing? Every time I login into Magento 2 in the Admin UI backend, I need to reindex & flush cache so my client's products can appear on the site.

Test of 2016-05-05 at 12:05 p.m. ET

(1) I truncated the cron_schedule table. Then after 1 minute here is the new table:

enter image description here

Here's the table after cron ran:

enter image description here

18
  • Please add your system detail too Mar 23, 2016 at 12:28
  • How do I do that or what specifically would you like to see @JayeshPatel Mar 23, 2016 at 12:29
  • I mean to say about your system OS, server, etc. Mar 23, 2016 at 12:30
  • May be it will help you devdocs.magento.com/guides/v2.0/config-guide/cli/…
    – Arunendra
    Mar 23, 2016 at 12:36
  • Right @Arunendra...that was the exact documentation page I used to setup the cron log entries. So why do I get my pop-up alert/error message? Mar 23, 2016 at 12:51

7 Answers 7

15

Truncate the cron_schedule table and see if it gets re-populated with scheduled tasks after a few minutes.

Rough, I know, but should give you an answer. Also, maybe it's worth doing this on a staging env. first.

Use:

truncate cron_schedule;

After a few minutes use:

select * from cron_schedule;
4
  • Thanks @GeorgeSchiopu. Doing that now. I'll post back in a few moments. And for what it's worth, I'd consider the site on a staging server at the moment as we are simply building the site at this point. Or at least trying to build it. Magento 2.0 seems very buggy and complex :( May 5, 2016 at 16:05
  • Take a look at my OQ with the latest amendment @GeorgeSchiopu. Thank you for helping. May 5, 2016 at 16:11
  • Cool, @H.Ferrence , glad that helped. May 6, 2016 at 6:41
  • @H.Ferrence can you mark my answer as "the chosen one" please, if it helped you solve the problem? It might prove beneficial for others to see that (...and it only took me more than 1yr to realise that! ). Thanks. Nov 2, 2017 at 21:48
1

Try specifying the user which is used to run the command. Don't use root for it, just the magento user. For example:

*/1 * * * * username /usr/local/bin/php -c /usr/local/lib/php.ini /home/abcdefg/public_html/bin/magento cron:run > /home/abcdefg/public_html/var/log/magento.cron.log&
*/1 * * * * username /usr/local/bin/php -c /usr/local/lib/php.ini /home/abcdefg/public_html/update/cron.php > /home/abcdefg/public_html/var/log/update.cron.log&
*/1 * * * * username /usr/local/bin/php -c /usr/local/lib/php.ini /home/abcdefg/public_html/bin/magento setup:cron:run > /home/abcdefg/public_html/var/log/setup.cron.log&

Example from my server (CENTOS 7) which is working fine:

*/1 * * * * myuser php -c /etc/php.ini /srv/html/path_to_magento/bin/magento cron:run > /srv/html/path_to_magento/var/log/cron.log
1

Seems to happen every once and awhile with my Vagrant machine. I got the same notice, all I had to do to get rid of it was to reindex data using:

php bin/magento indexer:reindex

1

You should check three things:

  • sudo service cron status to check if the service is running on the server

  • ls -la and check if your files user & group are the same as the one you configured on the cron crontab -u xxx -e

  • select * from cron_schedule and check if the cron table is being populated.

1

Following are useful:

  1. MySQL Table "cron_schedule" is your friend, open phpmyadmin or any mysql client, execute this:

select * from cron_schedule;

look for columns "created_at", "executed_at" and "messeges" can give you helpful information regarding cron working or ran.

enter image description here

  1. Use ssh to connect to server and execute the cron command manually if you see "Ran jobs by schedule.", it mean cron_schedule table has been updated.
1

As per the Magento Dev Docs,

All cron data is written to the cron_schedule table in the Magento database. The table provides a history of cron jobs, including:

  • Job ID and code
  • Status
  • Created date
  • Scheduled date
  • Executed date
  • Finished date

To see records in the table, log in to the Magento database on the command line and enter

SELECT * from cron_schedule;

-1

Open cron.php at root of the Magento directory and place:

Mage::log('cron is running', null, 'myCronLog.log'); 

Check this file after some interval and check it whether log file is generated or not under var/log. If it's generated then your cron is running.

2
  • 3
    This will only work for magento1, not magento2. Mage:: does no longer exist in magento 2, you need to use the loggerInterface as described here: magento.stackexchange.com/questions/92434/…
    – tecjam
    Mar 23, 2016 at 16:41
  • Does anyone know how to solve this issue in Magento 2 ? Mar 24, 2016 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.