Skip to main content
Question

"shutdown -r now" fails in LaunchDaemon script

  • October 26, 2017
  • 3 replies
  • 12 views

Forum|alt.badge.img+4

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

Forum|alt.badge.img+16
  • Honored Contributor
  • 330 replies
  • October 26, 2017

Maybe run the restart as a background task?

shutdown -r now &

Forum|alt.badge.img+16
  • Valued Contributor
  • 1002 replies
  • October 26, 2017

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
Forum|alt.badge.img+7
  • Jamf Heroes
  • 17 replies
  • February 13, 2023

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