Magento2 cron jobs

Discussion in 'ISPConfig 3 Priority Support' started by DylanPedro, May 1, 2018.

  1. DylanPedro

    DylanPedro Member HowtoForge Supporter

    Hi,

    I have added the following cron job for magento as advised in the following magento documentation:
    http://devdocs.magento.com/guides/v2.2/config-guide/cli/config-cli-subcommands-cron.html
    Code:
    /usr/bin/php7.0 [web_root]/magento2/bin/magento cron:run 2>&1 | grep -v Ran jobs by schedule >> [web_root]/magento2/var/log/magento.cron.log
    I have switched logging off for the cron in ISPConfig so it gets written to the correct file in the magento directory.

    When typing the following in the terminal I see the following errors:
    Code:
    journalctl|grep -wF 2604
    Code:
    May 01 12:55:02 server1 CRON[2604]: (web8) CMD (/usr/bin/php7.0 /var/www/clients/client0/web8/web/magento2/bin/magento cron:run 2>&1 | grep -v Ran jobs by schedule >> /var/www/clients/client0/web8/web/magento2/var/log/magento.cron.log >/dev/null 2>&1 #example.co.uk)
    May 01 12:55:21 server1 CRON[2593]: (CRON) error (grandchild #2604 failed with exit status 2)
    What am I missing here?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Ensure that you created the cronjob as full cron and not as jailed cron as the PHP interpreter is probably not available in the jail.
     
  3. DylanPedro

    DylanPedro Member HowtoForge Supporter

    I created the cron as the main admin user, it runs fine from command line but shows above errors when ran from the panel?
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    As admin you can create jailed and non jailed cronjobs. ensure that you created a non jailed one.
     
  5. DylanPedro

    DylanPedro Member HowtoForge Supporter

    Is this to do with the "Parent website" dropdown, as I cannot see how else to do this, when I click Sites > Cron Jobs I cant see any other options?
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    You're right, there is no setting for the admin. Please post the content of the cron file of this cronjob from /etc/cron.d/ folder.
     
  7. DylanPedro

    DylanPedro Member HowtoForge Supporter

    Code:
    MAILTO=''
    SHELL='/bin/sh'
    
    *       *       *       *       *       web8    /usr/bin/php7.0 /var/www/clients/client0/web8/web/magento2/bin/magento cron:run 2>&1 | grep -v Ran jobs by schedule >> /var/www/clients/client0/web8/web/magento2/var/log/magento.cron.log >/dev/null 2>&1 #example.co.uk
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    Ok, that's a non jailed cronjob, so a jail is notthe probem here. The command works like this without issues?

    sudo -u web8 /usr/bin/php7.0 /var/www/clients/client0/web8/web/magento2/bin/magento cron:run

    And the other question is, are you sure that the cronjob did not work? It might just be that it works fine and the jourtnalctl message is ok.
     
  9. DylanPedro

    DylanPedro Member HowtoForge Supporter

    Hi Till,

    So when I type it in the terminal I get this:
    Code:
    sudo -u web8 /usr/bin/php7.0 /var/www/clients/client0/web8/web/magento2/bin/magento cron:run
    Ran jobs by schedule.
    but when checking the syslog this is what it says for the cron itself:
    Code:
    May  2 12:04:01 server1 CRON[12690]: (web8) CMD (/usr/bin/php7.0 /var/www/clients/client0/web8/web/magento2/bin/magento cron:run 2>&1 | grep -v Ran jobs by schedule >> /var/www/clients/client0/web8/web/magento2/var/log/magento.cron.log >/dev/null 2>&1 #example.co.uk)
    May  2 12:04:21 server1 CRON[12685]: (CRON) error (grandchild #12690 failed with exit status 2)
    The database is showing the crons being added by the cron so why would jourtnalctl show this error?
    Is it anything to do with:
    Code:
    2>&1 | grep -v Ran jobs by schedule >> /var/www/clients/client0/web8/web/magento2/var/log/magento.cron.log >/dev/null 2>&1 #example.co.uk
     
  10. till

    till Super Moderator Staff Member ISPConfig Developer

    It is possible that the php script returns a non zero return code. That's why I asked if the tasks done by this cronjob are done because in that case, there is no error and just a wrong interpretion of the return code in the log.
     

Share This Page