Posted on 11-30-2020 12:59 PM
Hey folks, I am having an issue that is perplexing me to no end. I have both a LaunchDaemon and a LaunchAgent that run at boot.
From what I read, the LD should run when the computer is turned on, even before someone logs on. Currently its running when a user logs in. The script is setup to remove student accounts upon reboot. (its a lab where students use gigs of data at a time, this prevents the computer from running out of hard drive space).
The LA is a docutil file. I think I know what I need to do for that one (add in a line of script to wait until the Dock is loaded before running the docutil script).
Any idea why the LD is running when the user logs in, not when the computer starts?
Posted on 11-30-2020 02:20 PM
@kwoodard Do you have FileVault enabled? (That'd be unusual for a lab, but just in case) If so, you're not actually booted in to macOS until someone logs in. The FileVault login screen is basically a pre-boot stage waiting for someone authorized to unlock the drive before macOS boots.
And here's a good resource for LaunchDaemon/Agent troubleshooting: https://www.launchd.info
Posted on 11-30-2020 02:39 PM
No FileVault on these Macs... I have the exact same LD and LA on several other labs, and they work without issues. The difference is that these computers are on Catalina. These work fine on Mojave down.
Posted on 11-30-2020 07:17 PM
Can you post the LD and LA .plists for review?
Posted on 11-30-2020 11:28 PM
Here is the LD
<?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>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>LogoutCleanWNumbers</string>
<key>ProgramArguments</key>
<array>
<string>/Users/micro/bin/LogoutCleanWNumbers.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
The LA is in the same format, just triggers the docutil script. Is it the RunAtLoad bit thats messing things up? I need this to run when the computer boots up, before anyone logs into the computer.
Posted on 12-01-2020 12:53 AM
To me I would suspect the KeepAlive as being the problem, not the RunAtLoad.
KeepAlive is the line I use on Agents for launching Apps that I don't want to be quit. It will literally keep on launching them if they stop running.
I would suggest adding in a log line or two, to your script to tell you what time it started and finished, and what tasks were done. If it is set up as a Daemon it will run at boot, but with the KeepAlive in there it may well be running multiple times. The logs should be able to tell you.
Posted on 12-01-2020 06:01 AM
I'd agree that the KeepAlive block isn't necessary.
You might also change from
<key>ProgramArguments</key>
<array>
<string>/Users/micro/bin/LogoutCleanWNumbers.sh</string>
</array>
to
<key>Program</key>
<string>/Users/micro/bin/LogoutCleanWNumbers.sh</string>
since you're not passing parameters to the script being called
Posted on 12-01-2020 08:45 AM
Thank you @PaulHazelden and @sdagley ... I will give both of those suggestions a go and report back. The other thing that came to mind when I woke up at 230am, I am not 100% I verified that those plist files have the right permissions. I remember when I started using them way back when, I had a permissions issue when sending these files via ARD to the computers. I will check that as well.
Posted on 12-09-2020 09:59 AM
Turns out that I didn't verify that the permissions were what they needed to be. Hence they didn't work. Here is what I loaded into ARD and sent out to all of my computers... One of these days I will rename my TEST script. LOL Thanks for all the help!
sudo chown root:wheel /Library/LaunchDaemons/logoutcleanwnumbers.plist
sudo chmod 644 /Library/LaunchDaemons/logoutcleanwnumbers.plist
sudo chown root:wheel /Library/LaunchAgents/TEST.plist
sudo chmod 644 /Library/LaunchAgents/TEST.plist