user-pic

Launchd vs crontab

Vote 0 Votes

Is anyone using launchd on OS X to run run-periodic-task or any other MT script instead of crontab? I am wondering how you setup your plist.

2 Replies

| Add a Reply
  • I am using daemontools on Linux (there is an article on it over at Learning Movable Type, but nothing on Mac OS X. Hmmm...

    In a cursory look at the specification though, I imagine it would look something like this:

    <?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>Label</key>
        <string>com.movabletype.run-periodic-tasks</string>
        <key>Program</key>
        <string>/path/to/tools/run-periodic-tasks</string>
        <key>ProgramArguments</key>
        <array> 
            <string>run-periodic-tasks</string>
            <string>-daemon</string>
        </array>
        <key>StartInterval</key>
        <integer>3600</integer>
    </dict>
    </plist>
    

    I found this document very helpful:

    http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html

    • Okay I got it working and this is what I did.

      I create a file named com.movabletype.run-periodic-tasks.plist using the text-editor on my desktop. In that file I added the following:

      <?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.movabletype.run-periodic-tasks</string>
          <key>Program</key>
          <string>/path/to/tools/run-periodic-tasks</string>
          <key>ProgramArguments</key>
          <array>
              <string>run-periodic-tasks</string>
          </array>
          <key>StandardErrorPath</key>
          <string>/dev/null</string>
          <key>StandardOutPath</key>
          <string>/dev/null</string>
          <key>StartInterval</key>
          <integer>300</integer>
          <key>WorkingDirectory</key>
          <string>/path/to/mt</string>
      </dict>
      </plist>
      

      Now we need to move the file into place and set the permissions on it. You may be prompted for your password again:

      sudo mv ~/Desktop/com.movabletype.run-periodic-tasks.plist /Library/LaunchDaemons
      sudo chown root /Library/LaunchDaemons/com.movabletype.run-periodic-tasks.plist
      

      I can start and stop the script with:

      sudo launchctl load -w /Library/LaunchDaemons/com.movabletype.run-periodic-tasks.plist
      sudo launchctl unload -w /Library/LaunchDaemons/com.movabletype.run-periodic-tasks.plist
      

Add a Reply

Forum Groups

6 7

Last Topic: API password missing. by Absoblogginlutely! on Feb 26, 2008

62 142

Last Topic: Issues obtaining the Source by apidevlab on Jul 17, 2008

69 125

Last Topic: L10N by Voulf on Jul 16, 2008

24 55

Last Topic: installing allong side a vbulletin by Forgoten Dynasty on Jul 20, 2008

3 5

Last Topic: Share your success story, please. by Gianluca on Jun 20, 2008

code.sixapart.com

20 46

Last Topic: Installing in sub-folder by Lala on Jul 5, 2008