launchd cheatsheet
$ launchctl unload path/to/plist
$ launchctl load path/to/plist
$ launchctl start com.my.job.name
$ launchctl list | grep <myjobname>
launchd will send a SIGTERM
signal to the process, e.g. when launchctl unload
is called.
Sample job file
Place in ~/Library/LaunchAgents/com.iafisher.kg.jobserver.plist
<?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.iafisher.kg.jobserver</string>
<key>ProgramArguments</key>
<array>
<string>/Users/iafisher/.kg/bin/kg2</string>
<string>jobs</string>
<string>daemon</string>
<string>start</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/Users/iafisher/.kg/apps/jobserver/stdout</string>
<key>StandardErrorPath</key>
<string>/Users/iafisher/.kg/apps/jobserver/stderr</string>
<key>WorkingDirectory</key>
<string>/Users/iafisher/.kg/apps/jobserver</string>
<key>EnvironmentVariables</key>
<dict>
<key>PYTHONPATH</key>
<string>:</string>
</dict>
</dict>
</plist>