Occasionally the Caching service on macOS will stop working due to a network outage or a glitch on Apple’s end.
It’s a simple enough fix — all you have to do is turn the service off and on again. But how do you know that it’s offline? It’s easy if you use MunkiReport with the Caching module enabled.
Just save the code below as a script on your MunkiReport database server and set it up as an hourly cron job. It looks for caching activity reported in the last two hours, and kicks off an alert if no results are found. (Be sure to read the notes below.)
#!/bin/bash cachingactivity=`/bin/mysql munkireport -e "select \ collectiondate from caching where collectiondate > \ timestampadd(hour, +6, now()) order by \ collectiondate desc;"`; if [[ $cachingactivity == "" ]]; then echo "Caching service may be offline." fi
- The user who runs the script needs to have a MySQL credential stored in their .my.cnf file.
- Make sure cron is able to send you alerts. (Working MTA, and MAILTO=”user@domain” appears before this job is listed.)
- You may need to modify the timezone offset (+6) to something suitable for your location. I’m at UTC-8, so +6 means my script looks for caching server activity reported within the last two hours.
- Depending on how many clients there are, and whether any of them are on 24/7, you may need to adjust how far back your cron job is looking for records to avoid false error reports. Or only schedule it to check weekdays but not weekends.
- Obviously this doesn’t provide up-to-the-minute alerting, but it should still help you notice if something is wrong before anyone else does.
- With multiple caching servers, one could go down and you would not be alerted. The true purpose of this script is make sure that the caching service is working somewhere. It’s not concerned about calling out individual servers.