So I have a magento 2 instance running on ubuntu and I have some confusion about cron jobs. I know that magento 2 needs to have scheduled jobs in order to work correctly, but I am unable to find out how to get it set up correctly. I have read the dev docs, and followed this article. Currently, I'm not getting any errors I can see on the magento side, but I'm having issues with things changing correctly (i.e. changing menu options/product options). I have also changed the Missed if Not Run Within field to be longer than the jobs per this The cron_schedule table has all statuses as missed. I am not trying to do any custom jobs, just whatever default ones it needs to operate.
Magento 2 – Cron Job Status Always Missed/Not Running
cronmagento-cronmagento2
Related Solutions
Please Try This
It looks like you're using the default Magento cron.
If you want the AOE Scheduler to work you need to use the scheduler's cron instead - e.g.:
*/5 * * * * /bin/sh -f /home/cpanel_user/public_html/scheduler_cron.sh
FYI - the "heartbeat" task is a very lightweight cron job that runs every time, simply reporting that the scheduler is running. If your message is showing you that the heartbeat couldn't be found it likely means either that your cron isn't configured correctly, or there's a lock in place. You can try removing var/locks and the scheduler's lock which normally lives in /tmp if this is the case.
Hope It's helpful for any one.
I don't know what you are doing wrong but I can tell you how I set up Magento2 cron on a recent project.
I have been putting files inside the /etc/cron.d/
folder. This may be specific to certain Linux distributions and may be specific to how a particular Linux box is set up.
But in theory any file inside the /etc/cron.d/
folder will be run by cron. The syntax is slightly different but this method avoids having to work out which users' crontab to edit.
So:
# File : /etc/cron.d/magento2
# Run Magento2 cron every 7 minutes
*/7 * * * * magento_user php /var/www/html/magento2/bin/magento cron:run
[Linux commands* to create the file are
cd /etc/cron.d/
ls -l
vim magento2
]
ls -l
will show you the files here already.*you might prefer to type
nano magento2
instead ofvim magento2
,nano
being a slightly more user-friendly editor for those unaccustomed to editing text files in Linuxplease note: add a blank line at the end of this text file after the cron entry so the file ends with an empty line (this may be superstition but there is no harm in it)
To check that cron is running, on the Linux command prompt enter:
grep CRON /var/log/syslog
if that fails (Linux setups vary in where cron logs to) try
tail -n 100 /var/log/cron
[if that fails, hit the internet for advice such as this from Benjamin Cane]
You should see some log entries from various cron jobs that are running. If you do not see any recent entries then perhaps the Linux cron is not running but I think that would be unusual (and a whole different Q&A).
Eventually you should see a Magento entry in your Linux cron log due to the file you put in /etc/cron.d/
for example I see this:
CROND[3196]: (magento_user) CMD (php /var/www/html/magento2/bin/magento cron:run)
Then the main way I check Magento cron is behaving is to study the Magento database table cron_schedule
closely (using a tool such as MySQL Workbench).
If the Linux OS cron is calling Magento2 cron then you should see entries in this table with status pending
. Presently you should see status complete
or perhaps a useful error message to indicate where the Magento cron failed.
==================================
Adendum
I re-read your question.
cron.php
is from Magento 1.x so you should ignore any advice related to that- if you want to log to
<magento install path>/var/log/some-cron-file.log
then you do probably need to create that file first bycd /full-path-to-magento-install/var/log/
,ls -l
,touch some-cron-file.log
and then the harder part: give your new file the correct ownership and permissions for Linux cron to be able to write here. I don't know what they are for you but I know you can work that out. (but you don't really need to make your own log entries, the Linux system will most likely, and can be set to, log cron jobs tosyslog
or a dedicated log file)
Best Answer
Run these commands from your Magento directory:
and check if all jobs are running by schedule.