"shutdown -r now" fails in LaunchDaemon script

emmayche
New Contributor III

I'm trying to make things really simple for our users with a script that does quite a few things, including enrolling them into the JSS. It seems to me that the easiest way to do this is to push a script onto the computer, put a LaunchDaemon entry into /Library/LaunchDaemons, and force a reboot.

Up to this point everything works fine.

However, rebooting AFTER the script does its thing invariably fails. The system log says:

com.apple.xpc.launchd[1] (mil.navy.spawar.sd.stage1[113]): Service exited with abnormal code: 2

The timestamp is precisely when the "shutdown -r now" command is issued in the script. The script's process does get shut down, but the computer does not get restarted, and I have no idea why.

Does anyone have any ideas as to what I can check?

3 REPLIES 3

hkabik
Valued Contributor

Maybe run the restart as a background task?

shutdown -r now &

Look
Valued Contributor III

Or.

shutdown -r +1 &

This will give the script/daemon a minute to finish cleanly before restarting, I use this quite often in scripted policies because the built in restart in Casper seems to be rather unreliable.

DTB_Kirky
New Contributor III

I still have this issue and can't work it out - did anyone resolve?