How to update and upgrade homebrew with system daemon.
<?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.example.brew.upgrade</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/brew</string>
<string>upgrade</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>12</integer>
<key>Minute</key>
<integer>20</integer>
</dict>
<key>StandardErrorPath</key>
<string>/var/log/homebrew/upgrade.log</string>
<key>StandardOutPath</key>e
<string>/var/log/homebrew/upgrade.log</string>
</dict>
</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.example.brew.update</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/brew</string>
<string>update</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>12</integer>
<key>Minute</key>
<integer>10</integer>
</dict>
<key>StandardErrorPath</key>
<string>/var/log/homebrew/update.log</string>
<key>StandardOutPath</key>e
<string>/var/log/homebrew/update.log</string>
</dict>
</plist>
This two launchdaemon scripts provide scheduled updates and upgrade for homebrew packages.
It will run in the following way:
brew update every day at 12:10brew upgrade every day at 12:20Create directory to store logs:
$ sudo mkdir -p /var/log/homebrew
There are two options for running those scripts.
This will run tasks only when user is logged in.
~/Library/LaunchAgents/launchctl load providing absolute path to the plist fileThis way it is possible to run updates regardless of any user active login session. This method, however requires admin privileges, thus run commands below with sudo.
/Library/LaunchDaemons/chmod 644 /Library/LaunchDaemons/*.plistroot:wheel by running chown root:wheel /Library/LaunchDaemons/*.plistlaunchctl load providing absolute path to the plist file