Shammer's Philosophy

My private adversaria

LaunchDaemon plist file example

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTDPLIST1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
  <dict> 
    <key>Label</key> 
    <string>MyDaemon</string> 
    <key>UserName</key> 
    <string>root</string> 
    <key>GroupName</key> 
    <string>wheel</string> 
    <key>ProgramArguments</key> 
    <array> 
      <string>/usr/local/bin/mydaemon</string> 
      <string>arg1</string> 
      <string>arg2</string> 
      <string>arg3</string> 
    </array> 
    <key>StandardOutPath</key> 
    <string>/var/log/mydaemon-stdout.log</string> 
    <key>StandardErrorPath</key> 
    <string>/var/log/mydaemon-error.log</string> 
    <key>RunAtLoad</key> 
    <true/> 
  </dict> 
</plist>

This file is the same as following command.

# /usr/local/bin/mydaemon arg1 arg2 arg3

The key "StandardOutPath" is the STDOUT of above process, and "StandardErrorPath" is the STDERR of the one.
The key "RunAtLoad" means starting OS boot time at a time.

Finally, executing following command, /usr/local/bin/mydaemon will be started after next boot time. Please check file permission before executing this command, if the permission is the same as defined user and group, there is no problem. In above example, file permission should be root/wheel.

$ sudo launchctl load $PLIST_FILE_NAME

You can check by sudo launchctl list whether daemon configured succeeded or not.