LaunchDaemons are the new “init” for Mac OS X 10.4 onward.
I have successfully used it to start and run OpenVPN on Mac OS X 10.4 Server.
Below is the .plist file I created to start and run OpenVPN on Mac OS X 10.4
<?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>org.openvpn</string>
<key>OnDemand</key>
<false/>
<key>Program</key>
<string>/usr/local/sbin/openvpn</string>
<key>ProgramArguments</key>
<array>
<string>openvpn</string>
<string>--config</string>
<string>openvpn.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>TimeOut</key>
<integer>90</integer>
<key>WorkingDirectory</key>
<string>/etc/openvpn</string>
</dict>
</plist>
Once you have created the .plist file, you are ready to install and configure it with “launchctl”.
Just typing “sudo launchctl” on the command-line will take you into an interactive session with launchd!
Type “help” for instructions and a list of commands.
The following were the most helpful that I found… you can also use them on the command-line like the examples below. Assuming you have put the file about into /Library/LaunchDaemons/org.openvpn.plist, you can do the following:
“sudo launchctl load /Library/LaunchDaemons/org.openvpn.plist” to tell launchd about your new daemon.
“sudo launchctl unload /Library/LaunchDaemons/org.openvpn.plist” to uninstall your daemon.
“sudo launchctl start org.openvpn” to start the daemon.
“sudo launchctl stop org.openvpn” to cause launchd to stop being obsessive about the daemon and let it die.
With the .plist file shown above, launchd automatically restarts OpenVPN when it crashes and the process is no longer running.
Hope that helps someone!
