Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.