How do I ensure that my launch daemon will work properly?

howie_isaacks
Valued Contributor II

I have recently created a script that I will be using for a monthly policy to encourage users to reboot their Macs regularly. I'm using Swift Dialog to show a prompt to users to reboot. I am giving them the ability to defer rebooting up to 3 times. I also added a function in the script that will check if either Zoom or Teams is in a meeting. The Swift Dialog window won't appear if either app is in a meeting. Instead a launch daemon is installed and loaded to ensure that the policy runs again. When a user defers, the deferral time is written to a PLIST. The PLIST tracks the time and date of each deferral, how many times the user has deferred, and how many deferrals are remaining. The launch daemon is also installed after a deferral. I want the launch daemon to launch the policy again 1 day after the user defers or after the script finds that the user is in a Zoom or Teams meeting. In my tests, I set the StartInterval to 300 seconds so I wouldn't need to wait a full day. After I saw that the policy was being launched by the launch daemon, I changed the StartInterval value to 86,400 seconds. I have not seen the policy relaunch on my Mac when I have the StartInterval set at that value. I currently have RunAtLoad set to false since this was causing the policy to relaunch immediately after a deferral. The launch daemon also runs as root. The only thing this launch daemon does is run "/usr/local/jamf/bin/jamf policy -event monthly-reboot". When a user reboots, the script unloads the launch daemon and deletes it and the deferral PLIST. Does anyone have any ideas why my launch daemon isn't working as expected when I set the StartInterval to a full day? It works perfectly when I set it at a lower value for testing. I'm posting the launch daemon below. I have written a lot of launch daemons in the past. They all worked. I took my company name out of the Label string since they don't like me to identify who I work for here 🤷🏽‍

 

<?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.myCompany.Reboot</string>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/local/jamf/bin/jamf</string>
		<string>policy</string>
		<string>-event</string>
		<string>monthly-reboot</string>
	</array>
	<key>RunAtLoad</key>
	<false/>
	<key>StartInterval</key>
	<integer>86400</integer>
	<key>UserName</key>
	<string>root</string>
</dict>
</plist>

 

  

4 REPLIES 4

jamf-42
Valued Contributor II

while I've not used it, this looks like you could use this rather than StartInterval, using StartCalendarInterval and just Key - Day 1

jamf42_0-1721227213710.png

https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters...

more examples of StartCalendarInterval here:

 

https://alvinalexander.com/mac-os-x/launchd-plist-examples-startinterval-startcalendarinterval/

howie_isaacks
Valued Contributor II

This is interesting. I will try it on my own MacBook Pro. I'm waiting to hear back from my testers to find out if the Swift Dialog window reappeared 24 hours later. I don't care if it ever works on my computer since I shut down this system at the end of day every Friday. The policy won't ever be scoped to my Mac.

Deku91
New Contributor III

howie_isaacks
Valued Contributor II

My script works similar to this. That post has given me an idea on how to improve my own script so thanks for posting this. Right now, I'm focused on making sure my launch daemon works. People who I have testing this say they are seeing the policy launch a day after they deferred so that is a good sign that it's working. The reason why I am worried about this is because it's not happening on my own Mac. I don't want the issue to also occur on other systems.