I've be tasked with creating a deferral prompt for a Managed OS workflow. I've gotten everything figured out....except for LaunchD to actually trigger the deferred policy at a later time. Here's the problem section of code.
## Writes a simple script that exists just to call the deferred policy
echo "/bin/launchctl unload /Library/LaunchDaemons/managedOS.plist" >> /Library/Application Support/JAMF/callManagedOSCountdown.sh
echo "/bin/rm /Library/LaunchDaemons/managedOS.plist" >> /Library/Application Support/JAMF/callManagedOSCountdown.sh
echo "/usr/local/bin/jamf policy -event $policyTriggerDeferred &" >> /Library/Application Support/JAMF/callManagedOSCountdown.sh
chown root:wheel /Library/Application Support/JAMF/callManagedOSCountdown.sh
chmod 644 /Library/Application Support/JAMF/callManagedOSCountdown.sh
## WRITE LAUNCHDAEMON
#Create the plist
defaults write /Library/LaunchDaemons/managedOS.plist Label -string "managedOSDeferral"
#Add program argument to have it run the update script
defaults write /Library/LaunchDaemons/managedOS.plist ProgramArguments -array -string /bin/sh -string "/Library/Application Support/JAMF/callManagedOSCountdown.sh"
#Set the run inverval to run
defaults write /Library/LaunchDaemons/managedOS.plist StartInterval -integer $delayChosen
#Set run at load
defaults write /Library/LaunchDaemons/managedOS.plist RunAtLoad -boolean yes
#Set ownership
chown root:wheel /Library/LaunchDaemons/managedOS.plist
chmod 644 /Library/LaunchDaemons/managedOS.plist
## LOAD LAUNCHDAEMON
/bin/launchctl load /Library/LaunchDaemons/managedOS.plist
I tried using cat
to write the script locally and it always failed. Echoing in works, but is less than ideal. That script runs correctly when run manually on the machine.
As for the LaunchDaemon aspects, I have no idea what's going on. Sometimes it loads with a status of 127. Most of the time nothing happens. No errors to standard output. No logging of any kind even if I add that in. No feedback when it's loaded manually on the machine rather than through the script. I'm still new to LaunchD in general, so I have no idea what I'm missing here. Any suggestions?
I've been testing on macOS 10.12 through 11 with same results on all platforms.