Hi all,

I'm having trouble getting my cron script automated running Drupal 5.X on an Apple XServe (running the latest Leopard Server OS). I understand that launchd is the 'Apple' way to go about doing this, but so far I haven't had much luck. The first time I tried to set up a cron script using launchd, I crippled the server and it needed to be restored from a time machine backup (I assume that I inadvertently messed up another launchd script when I loaded mine as the server from that point forward refused to get a valid WAN IP address - but I digress).

Does anyone know of a walkthrough / tutorial on how I should set this up for Leopard Server? Anyone out there with a similar setup and this working OK? After my first dismal failure, I'm nervous playing around with the system-wide launchd and would really appreciate a 'hold my hand' walkthrough on how to set this up. Thanks for any tips / advice,

Mike

Comments

thaeez’s picture

Bump...

thaeez’s picture

Anyone?

NiklasBr’s picture

Anyone?

robguy’s picture

Apple has kept Cron in Leopard's Darwin underpinnings (though Apple considers cron "deprecated," in favor of launchd, it will still allow some cron jobs to run. One such cron job is Drupal's cron.php.

Steps. In Terminal:
1. Type su and give your administrative password when prompted
2. Type crontab -e at the prompt
3. Cursor to the bottom of the last cron job. Press i on your keyboard to go into insert mode. Construct your cron job thus:
45 * * * * /path/to/drupal/cron.php
(press escape key to exit insert mode) Then ...
Type ZZ (Must be capital letters -- exits crontab and saves it)
(verify the cron job details by typing crontab -l at the prompt)

For your information: Cron jobs are stored in /usr/lib/cron/tabs (listed by username).

There is also a Drupal module that will run your drupal cron job even if you can't create a cron job under your user name. Its name is "Poor Man's Cron," and you can find it in the modules downloads page on drupal.org. It works in both Drupal 5 and 6. Works like a charm whether you're an administrator on your Mac or not.

=======================
You're never alone with schizophrenia.

NiklasBr’s picture

Many thanks to you!

NiklasBr’s picture

Still, thanks for taking your time to answer.

However, I tried just that and cron is not running. Tried restarting the server: nothing. Tried allowing the exec bit in cron.php: nothing. This with a otherwise very stable OS X (10.5.3) installation.

laken’s picture

Doubt anyone is still reading, but in case anyone else finds this page:

The OP left out an important part of the cron command - it should look like this

45    *   *   *   *   wget -O - -q http://www.example.com/cron.php

more detail and complete explanation here

Rainy Day’s picture

Since wget is not installed on MacOS X by default, and curl is, this might work best:

#minute   hour   mday   month   wday   command
45        *      *      *       *      /usr/bin/curl -s http://www.example.com/cron > /dev/null 2>&1

Note: the “-s” switch is probably superfluous since the “> /dev/null 2>&1” will ensure that any and all output is suppressed. But it is there for good form.

Also, since this does not need to be a privileged process, might as well let the “nobody” user perform it. To create/edit nobody’s crontab:

  sudo crontab -u nobody -e

webservant’s picture

This is pretty easy to do using launchd. Here are the steps to making this happen.

First, this assumes you understand basic terminal commands and are comfortable using terminal. I am not responsible for any thing that may go wrong.

That said, you need to replace any references to a website with your own website

In terminal follow these steps
1. Type: sudo pico /Library/LaunchDaemons/com.the-website.cron.plist
2. past in the xml script shown below.
3. Modify the script to fit your website
4. Type: control+x
5. Type: y (to save)
6. Type launchctl load /Library/LaunchDaemons/com.the-website.cron.plist

In the script below, you must change the http line to your website. Also you must pick a name for the file. com.the-website.cron.plist should be changed to match your website, then you must also change the label string inside the script to match the name of the file without the .plist
This works on my server, and you should be able to do this in about 6 steps. To troubleshoot problems, watch the console messages in the Console app.

*****************Begin: Copy the code between this line and the end line.**********************
<?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.the-website.cron</string>
        <key>ProgramArguments</key>
        <array>
                <string>curl</string>
                <string>-s</string>
                <string>http://www.the-webwite.com/cron.php</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StartInterval</key>
        <integer>3600</integer>
                <key>UserName</key>
        <string>_www</string>
        <key>GroupName</key>
        <string>_www</string>
</dict>
</plist>
***********************End Line do not copy begin or end lines********************
tsunami7’s picture

Just a tip for anyone who saw this and wanted to try it out on the client version of OS X. Change _www to simply www. You'll save yourself some frustration.