0

Can launchd on OSX (specifically Mountain Lion) be configured to work like watchdog, monitoring processes, after having launched them, to keep them alive? If so, how?

Magellan
  • 4,431
  • 3
  • 29
  • 53
pistacchio
  • 447
  • 7
  • 18

1 Answers1

0

Create a .plist file telling launchd what to launch, when to launch it, and what to do when it exits. Here's a very simple example:

<?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>local.someidentifier</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/path/to/executable</string>
    </array>
</dict>
</plist>

There are lots more options; see Apple's developer docs and the launchd.plist man page. Once the file is created, place it in /Library/LaunchDaemons/local.someidentifier.plist (note that the filename should match the "Label" entry). Set its owner to root, group to wheel, and permissions to 644. It'll be loaded when you restart the computer, or you can load it manually with sudo launchctl load /Library/LaunchDaemons/local.someidentifier.plist

Gordon Davisson
  • 11,036
  • 3
  • 27
  • 33