Moodle
  1. Moodle
  2. MDL-23967

Cron script no longer works properly in CLI 'mode' - needs warning operation has changed from 1.9

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0, 2.1.1, 2.2
    • Fix Version/s: 2.0.5, 2.1.2
    • Component/s: Administration
    • Labels:
      None
    • Rank:
      454

      Description

      admin/cron.php's loading of config.php seems to have been simplified (compared to the 1.9) version and this results in it no longer working as a CLI script when called from cron. E.g...

      /usr/local/bin/php -f /home/moodle2/moodle/admin/cron.php

      results in config.php not being found. I suppose that adding a cd to the admin directory is a workaround but it seems like a backward step.

        Activity

        Hide
        Iñaki Arenaza added a comment -

        I don't know if this is documented elsewhere (in addition to the top of the script itself), but admin/cron.php is only meant to be executed from the web. If you want to run cron from the command line, you need to use admin/cli/cron.php

        Saludos.
        Iñaki.

        Show
        Iñaki Arenaza added a comment - I don't know if this is documented elsewhere (in addition to the top of the script itself), but admin/cron.php is only meant to be executed from the web. If you want to run cron from the command line, you need to use admin/cli/cron.php Saludos. Iñaki.
        Hide
        Howard Miller added a comment -

        Ok... but as lots of people will make the same mistake, why not detect an attempt to run in CLI mode and print a message. As this is the recommended way to run Cron these days hundreds of people who upgrade from 1.9 and don't change their crontabs will hit this.

        Show
        Howard Miller added a comment - Ok... but as lots of people will make the same mistake, why not detect an attempt to run in CLI mode and print a message. As this is the recommended way to run Cron these days hundreds of people who upgrade from 1.9 and don't change their crontabs will hit this.
        Hide
        Howard Miller added a comment -

        Have thought about it. This will break things for loads of people who upgrade. If we have to change the way cron works (not sure why) then it needs some sort of warning if you have set it up wrongly. Surely, this is a regression. If you really think I'm mad or missing the point feel free to re-close

        Show
        Howard Miller added a comment - Have thought about it. This will break things for loads of people who upgrade. If we have to change the way cron works (not sure why) then it needs some sort of warning if you have set it up wrongly. Surely, this is a regression. If you really think I'm mad or missing the point feel free to re-close
        Hide
        Jason Turnbull added a comment -

        Just to add my two cents: I spent over half a day trouble shooting why my LDAP & cron weren't firing up.

        It was as simple as changing the path in my batch files, but this isn't documented anywhere. I eventually found it in a forum thread as an answer to this question.

        I understand Moodle 2.0 is still RC2 and work is focussed on getting it out, but some documentation would be great.

        Show
        Jason Turnbull added a comment - Just to add my two cents: I spent over half a day trouble shooting why my LDAP & cron weren't firing up. It was as simple as changing the path in my batch files, but this isn't documented anywhere. I eventually found it in a forum thread as an answer to this question. I understand Moodle 2.0 is still RC2 and work is focussed on getting it out, but some documentation would be great.
        Hide
        Dan Poltawski added a comment -

        I agree this could catch a lot of admins out, so here is a patch for integration.

        It should cherry-pick onto 21_STABLE & 20_STABLE

        Show
        Dan Poltawski added a comment - I agree this could catch a lot of admins out, so here is a patch for integration. It should cherry-pick onto 21_STABLE & 20_STABLE
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Integrated, thanks!

        Note for testers: Please test this under 21_STABLE

        Show
        Eloy Lafuente (stronk7) added a comment - Integrated, thanks! Note for testers: Please test this under 21_STABLE
        Hide
        Andrew Davis added a comment -

        As expected if I run /admin/cron.php from the command line I get an error message which is a little unusual in that its really helpful.

        ERROR: This script no longer supports CLI, please use admin/cli/cron.php instead

        /admin/cron.php works fine from the browser as is expected.

        Running /admin/cli/cron.php works fine.

        Running /admin/cli/cron.php from the browser also results in an error as expected.

        Command line scripts can not be executed from the web interface

        Show
        Andrew Davis added a comment - As expected if I run /admin/cron.php from the command line I get an error message which is a little unusual in that its really helpful. ERROR: This script no longer supports CLI, please use admin/cli/cron.php instead /admin/cron.php works fine from the browser as is expected. Running /admin/cli/cron.php works fine. Running /admin/cli/cron.php from the browser also results in an error as expected. Command line scripts can not be executed from the web interface
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Sent upstream and closing, many thanks!

        Show
        Eloy Lafuente (stronk7) added a comment - Sent upstream and closing, many thanks!

          People

          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: