2

I want to use launchd to update my MacPorts tree periodically (i.e. port selfupdate.

I have created /Library/LaunchDaemons/org.macports.selfupdate.plist:

$ ls -l /Library/LaunchDaemons/org.macports.selfupdate.plist
-rw-r--r--  1 root  wheel  669  8 Nov 12:49 /Library/LaunchDaemons/org.macports.selfupdate.plist

It has the following contents:

<?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>org.macports.selfupdate</string>
<key>ProgramArguments</key>
<array>
    <string>/opt/local/bin/port</string>
    <string>selfupdate</string>
</array>
<key>StandardOutPath</key>
<string>/var/log/org.macports.selfupdate.log</string>
<key>StandardErrorPath</key>
<string>/var/log/org.macports.selfupdate.err</string>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>604800</integer><!-- 1 week -->
</dict>
</plist>

I've loaded it and verified that it's loaded:

$ launchctl list | grep macports
-   78  org.macports.selfupdate

But it doesn't look like it actually run.

$ port info wireshark
Warning: port definitions are more than two weeks old, consider updating them by running 'port selfupdate'.
wireshark @1.12.8_3 (net)
...

What am I missing?

1

You probably put the plist in ~/Library/LaunchAgents/. Since /opt/local is owned by root:wheel (that's at least the default), you don't have the proper permissions to write to certain necessary folders (e.g. /opt/local/var/macports/sources/rsync.macports.org/release/tarballs/tmp). The log files (i.e. /var/log/org.macports.selfupdate.log/err) neither can be created, because only root can write to /var/log/.

So run the selfupdate service as launch daemon:

  • Remove the launch agent from the launchd database:

    launchctl remove org.macports.selfupdate
    
  • Move the plist to /Library/LaunchDaemons/:

    sudo mv ~/Library/LaunchAgents/org.macports.selfupdate.plist /Library/LaunchDaemons/org.macports.selfupdate.plist
    
  • Modify owner and permissions:

    sudo chown root:wheel /Library/LaunchDaemons/org.macports.selfupdate.plist
    sudo chmod 644 /Library/LaunchDaemons/org.macports.selfupdate.plist
    
  • Load the daemon:

    sudo launchctl load /Library/LaunchDaemons/org.macports.selfupdate.plist
    

Such launch daemon is run with root permissions and can update MacPorts data as well as write to /var/log/.

  • It was actually in /Library/LaunchDaemons. Isn't that where it should be? In the meantime I'll check my permissions. – Stephen Rasku Nov 8 '16 at 23:44
  • @StephenRasku Did you launch the daemon initially with sudo launchctl load /Library/LaunchDaemons/org.macports.selfupdate.plist? What does the selfupdate error log/selfupdate normal log reveal? – klanomath Nov 8 '16 at 23:48
  • I did launch it that way. I didn't see any logs when I did it. I just re-did it and added diagnostics and it looks like rsync is not connecting to the proxy for some reason. – Stephen Rasku Nov 8 '16 at 23:59
  • I just ran a port install command from the command line and that failed too. I didn't have that problem before. I'll take a look at it in the morning. – Stephen Rasku Nov 9 '16 at 0:03
  • @StephenRasku The file /var/log/org.macports.selfupdate.log should at least contain some details. I have tested this in a VM (first in ~/Lib/LaunchAgents/, then as a launch daemon in /Lib/LaunchD.../. The first attempt failed of course - the second wrote some lines (i.e port's version etc) – klanomath Nov 9 '16 at 0:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .