I have a cron-like launchd script (
StartCalendarInterval) that does a backup of some website data once per day:
<?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.backup</string> <key>ProgramArguments</key> <array> <string>/Volumes/Example/backup.sh</string> </array> <key>StartCalendarInterval</key> <array> <dict> <key>Hour</key> <integer>2</integer> <key>Minute</key> <integer>15</integer> </dict> </array> <key>StandardErrorPath</key> <string>/var/log/com.example/backup_error</string> <key>StandardOutPath</key> <string>/var/log/com.example/backup_output</string> </dict> </plist>
In rare cases it might go wrong when the Internet is not available. The backup.sh script then sets a proper error code that is larger than 0.
Now I would like that the script is automatically relaunched an hour later after an error. And again and again until there is no error. But not after 24 hours to avoid two instances of the script running at the same time.
I believe this must be possible with
SuccessfulExit. My problem is that
SuccessfulExit is linked to
KeepAlive. I do not want the script to run all the time, but just once a day via the
Is my task doable directly with launchd? Or should I simply add
wait 1 hour and try again after error to my script? The script would require resources all the time when set up like this. I would like to avoid this.