Last updated April 14, 2011. Created by robballan on August 29, 2009.
Edited by olafveerman, scott_bluenorth_ca, Rainy Day. Log in to edit this page.

Drupal documentation refers to running cron jobs periodically. But OS X Server (at least Leopard Server) has a kernel bug that results in a log message from cron jobs to the effect “Could not setup Mach task special port 9: (os/kern) no access”. Not a joyful message to come across, though it appears to be harmless.

In addition, OS X doesn’t come with wget, so the suggested cron call in the Drupal docs doesn’t work anyhow.

To avoid both of these problems, put a call to curl in a launchd daemon .plist file (e.g. /Library/LaunchDaemons/drupal-cron-call.plist), thusly:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
    <string>com.{domain-name}.drupal-cron</string>
  <key>UserName</key>
    <string>nobody</string>
  <key>GroupName</key>
    <string>_www</string>
  <key>ProgramArguments</key>
    <array>
      <string>/usr/bin/curl</string>
      <string>-s</string>
      <string>http://localhost/{drupal-subdirectory/}cron.php</string>
    </array>
  <key>RunAtLoad</key>
    <true/>
  <key>StartCalendarInterval</key>
    <dict>
      <key>Minute</key>
      <integer>09</integer>
    </dict>
  </dict>
</plist>

Then launchctl load /Library/LaunchDaemons/drupal-cron-call.plist and enjoy.

Notes:

  • http://localhost/{drupal-subdirectory/}cron.php” might be replaced with “http://{domain-name}/cron.php” for a production server.
  • Be sure to replace {domain-name} and/or {drupal-subdirectory/} placeholders (in sample .plist file above) with appropriate values.
  • For non-production environments, StartCalendarInterval, which always runs at nine minutes past the hour in this example, should perhaps be replaced with StartInterval, which always runs after a specified number of seconds have elapsed (since the last run). For production environments, it’s nice to run cron by the clock, but development computers may be asleep during arbitrary times and thus benefit from the elapsed-time approach. To change this, replace:
      <key>StartCalendarInterval</key>
        <dict>
          <key>Minute</key>
          <integer>09</integer>
        </dict>

    with:
      <key>StartInterval</key>
        <integer>3600</integer>
    (This example runs every hour.)

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

Awesome! This also works on my client machine running OS X 10.4.11. This should work on any Mac using OS X 10.4+. I was able to get it running for my Multi-Site setup, using my cronall script. Look for my comment on http://drupal.org/node/246091, if you're interested.

One alteration was necessary though. You have to change the GroupName to www, instead of _www. I'm not sure if this is a 10.4 -> 10.5 change, or if it's a Client vs Server variation.

Apple's documentation for OS X 10.6 Server claims that the user and group are www, instead of _www, so it could just be an error in the above code.

Michael
Martian Graphix, Inc

MAMP uses port 8888 so as to be totally separate from the regular Mac-installed server (I'm running OS 10.5.8).

I'm a total newbie and I keep running into something new that's scary. Everything says it's really important to do this or that before you do such and such.. I'm practically immobilized.

I had no idea... it seems everyone who installs Drupal is savvy about cronall scripts, on and on except for me :-(

I'd just like to know if I still need this "altered" form of script you mention... or what?
I'm baffled and I'm still just setting up my localhost.
Gee whiz.

Mike Storer

As a newbie I asked the forum about this messy situation and was told to forget it all and just download the following module:

http://drupal.org/project/poormanscron

Now, if someone can just get this info into the Handbook and strike out all the outdated grief above...

Mike Storer

Works just fine. Thanks.

mastorer, sadly poormanscron is not a solution for everyone, nor IMHO a good solution for a site seriously depending on timed actions. But thanks for your tip, I'm sure it will help someone though. But the data above indeed can help someone, there fore in most of the time better just to leave it.

FYI, the code snippet works as is (i.e. www group). I'm on 10.6...

Thanks for the code snippet and explanations...
gary

Gary

---
Victoria, BC
Canada

If I'm running Drupal 6 off my localhost ("Snow Leopard" Mac OSX 10.6.8) do I need to update:

<string>com.{domain-name}.drupal-cron</string>

...to...
<string>localhost.drupal-cron</string>

or something else equivalent?

The reason I ask is that when I run the following command (with the code referenced below) both with and without sudo:
sudo launchctl load /Library/LaunchDaemons/drupal-cron-call.plist
...I get the message "launchctl: no plist was returned for: /Library/LaunchDaemons/drupal-cron-call.plist
nothing found to load."

Here's my drupal-cron-call.plist file (intending to run cron ever 2 minutes):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
    <string>com.{domainname}.drupal-cron</string>
  <key>UserName</key>
    <string>nobody</string>
  <key>GroupName</key>
    <string>www</string>
  <key>ProgramArguments</key>
    <array>
      <string>/usr/bin/curl</string>
      <string>-s</string>
      <string>http://localhost:8082/cron.php</string>
    </array>
  <key>RunAtLoad</key>
    <true/>
  <key>StartInterval</key>
    <integer>120</integer>
</plist>

Could this be an issue with the port number? Perhaps I need to reference my Mac's computer name instead of localhost (ex.: http://mymacname.local:8082/cron.php)?

Please note that I can manually run http://localhost:8082/cron.php or http://mymacname.local:8082/cron.php successfully from my browser.

Thoughts?
_rs

I had done this last year, but upon trying a different CRON plist tonight, I got the same error as you due to a syntax error.

Instead of:
com.{domainname}.drupal-cron

Try:
local.mymacname:8082.drupal-cron

.. don't know about the non-default port though, as mine uses the default port 80 (so no port # necessary)

HTH
gary

Gary

---
Victoria, BC
Canada