Here’s the rub: the CLI application for updating MacPorts, “port” likes to have a home environment variable populated. Apparently this happens when executing port from a CLI. When running from launchd, however, $HOME is empty and thus the script dies.
The fix is trivial. You need to add the following to your user daemon (it needs to run as root, so user daemon it is):
<key>EnvironmentVariables</key> <dict> <key>HOME</key> <string>/var/root</string> </dict>
Here is the full context. (the path to your user daemons is at:)
/Library/LaunchDaemons System-wide daemons provided by the administrator.
<?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>EnvironmentVariables</key> <dict> <key>HOME</key> <string>/var/root</string> </dict> <key>Disabled</key> <false/> <key>KeepAlive</key> <false/> <key>Label</key> <string>com.ksk.updateMacports</string> <key>ProgramArguments</key> <array> <string>/usr/bin/update-port.sh</string> </array> <key>RunAtLoad</key> <false/> <key>StartInterval</key> <integer>43200</integer> </dict> </plist>
Hat-tip: Arno, here.
