Note: You are currently viewing documentation for Moodle 3.1. Up-to-date documentation for the latest stable version of Moodle is probably available here: Cron with MAC OS X.

Cron with MAC OS X

From MoodleDocs

NOTE: This describes setting up Moodle's cron using OSX's launchd system. However, since OSX is a variant of Unix, cron is also an option. It should be noted, however, that OSX cron is actually managed by launchd.


The following information was originally publish by Ralf Krause in the Step by Step Installation on a Mac OS X Server.

launchd

In Mac OS X 10.5+ you will find the system daemon launchd for this service. This daemon offers a standardized interface to any user and all programs started automatically by the system. Please look at http://developer.apple.com/macosx/launchd.html for more informations about the configurations and all parameters.

The service should get the web page http://path.to.your/moodle/admin/cron.php every few minutes. The configuration will be done by the file named moodle4mac.cron.plist which must be placed in the system folder /Library/LaunchDaemons/ ... surely you can use any other file name but it should say something about the function of the service. The extension must be .plist. After any reboot of your Mac server the cron service will start automaticly because the file is placed in the correct system folder.

NOTE: Check the Cron settings to make sure running the web version of Moodle's cron is permitted.

Use the graphical way

You can use Lingon (no longer supported, unfortunately) to add a new daemon plist or to edit one. It produces the same text as you can write in your text editor. http://sourceforge.net/projects/lingon/files/

Lingon screenshot

Use a text editor

Please use a text editor to write the needed file. You can open the Terminal and use the system editors vi or pico. But you can also write the text file with any GUI text editor ... I mostly use TextWrangler ... but do NOT take an editor for formatted texts like Microsoft Word or OpenOffice Writer. You must get pure text!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" 
     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key><false/>
<key>Label</key><string>moodle4mac.cron</string>
<key>ProgramArguments</key>
<array>
     <string>curl</string>
     <string>-s</string>
     <string>http://your-server-address/moodle19/admin/cron.php</string>
</array>
<key>RunAtLoad</key><true />
<key>StartInterval</key><integer>300</integer>
<key>StandardErrorPath</key><string>/dev/null</string>
<key>StandardOutPath</key><string>/dev/null</string>
</dict>
</plist>

The label string must be the same as the file name is but without the extension .plist. Save the text file /Library/LaunchDaemons/moodle4mac.cron.plist. The owner of the file must be set to the system user root with the following:

sudo chown root /Library/LaunchDaemons/moodle4mac.cron.plist

If you use a site with SSL (ie: it has an https:// protocol) you either need to have your SSL certificates listed for use by the CURL utility (see these docs for more details) OR you must use the '-k' switch in addition to the '-s' switch used above; your arguments line would then read: `<string>-s -k</string>`.

That's all, really!

How to start and stop the cron service

You can start the new cron service in the Terminal.

sudo launchctl load /Library/LaunchDaemons/moodle4mac.cron.plist

The following command would stop the service. If you want to activate changes in the cron service you need to unload and then to load the daemon again.

sudo launchctl unload /Library/LaunchDaemons/moodle4mac.cron.plist

Only one service for two servers?

For my server I needed to have a cron service for to instances moodle19 and moodle20 ... no problem ... with the typo moodle[19-20] I will get a cron service for both.

curl -s http://your-server-address/moodle[19-20]/admin/cron.php

To see if the cron service works correctly you should look at the access.log of your web server. The cron.php should be accessed every 5 minutes ... on my server for both Moodle instances moodle19 and moodle20 ... oh yes, it works!!

192.168.0.220 - - [30/Jul/2009:22:10:56 +0200] "GET /moodle19/admin/cron.php HTTP/1.1" 200 1136
192.168.0.220 - - [30/Jul/2009:22:10:57 +0200] "GET /moodle20/admin/cron.php HTTP/1.1" 200 1403
192.168.0.220 - - [30/Jul/2009:22:11:18 +0200] "OPTIONS * HTTP/1.0" 200 -
192.168.0.220 - - [30/Jul/2009:22:15:56 +0200] "GET /moodle19/admin/cron.php HTTP/1.1" 200 735
192.168.0.220 - - [30/Jul/2009:22:15:57 +0200] "GET /moodle20/admin/cron.php HTTP/1.1" 200 964
192.168.0.220 - - [30/Jul/2009:22:20:56 +0200] "GET /moodle19/admin/cron.php HTTP/1.1" 200 1136
192.168.0.220 - - [30/Jul/2009:22:20:57 +0200] "GET /moodle20/admin/cron.php HTTP/1.1" 200 1365