Way to gracefully restart a Mac from the JamfHelper Windows

rdagel
New Contributor II

I have a popup that is displayed after a Mac installs updates that require a restart. One of the buttons says Restart. I am using an apple script in a shell script to trigger the restart, but it does not work when it is run from the JSS as I believe it is running as root and not the current user. If you run the shell script locally it works fine. If you have it in the JSS and it is triggered from the JSS it does not work. This is the trigger I am using:

osascript -e 'tell application "System Events" to restart'

It is not working currently. Does anyone know of a way to restart from a JamfHelper window?

4 REPLIES 4

kbingham
New Contributor III

You can create an empty policy that forces an immediate restart and a trigger like rebootNow then call it with

jamf policy -event rebootNow

In Jamf Helper

talkingmoose
Honored Contributor II

Can you give a little more detail about how you're wanting to manage the user's experience?

You'd have to be calling your jamfHelper script using a policy and policies have a Restart option built in to the policy settings. You also mention the pop-up appears after you've installed software and "One of the buttons says Restart". What are the other buttons?

It sounds like you're trying to allow the user to complete the software installs by clicking the Restart button but you're offering them something else, which is probably not a good idea. When you install software that requires a restart, you should immediately restart the Mac and not allow an option to defer.

An alternative workflow would be to display the dialog before installing the updates and allow deferrals. Only if the user says "OK" or "Restart" would you install the software. Once the software is installed then use the Restart setting in the policy and "Restart Immediately".

Avoid putting restart commands in your scripts if you can. You want your policy to complete and the Mac to report completion to Jamf Pro before the restart. If you need to put a restart in your script, you can give it a slight delay and send it to a background process using something like:

shutdown -r +1 &

This restarts the computer in one minute. The ampersand sends this to another process to allow the script to complete.

You may event want to use jamfHelper's feature to display a full screen message to the user to prevent doing anything while Jamf Pro is installing the updates.

marklamont
Contributor III

we use the same method as @talkingmoose outlines extensively. works great. just make sure the timeout covers off whatever is remaining to do so it has time to finish and report back to the jamf server or you end up not knowing the policy has run. Ideally make sure it's the last item in the last script.

el2493
Contributor II

We also use the same method at @talkingmoose, though I do +2 (I also haven't used the "&" but will look into this now). As @marklamont said if you don't include the timeout/delay it won't register that the policy has run, and I've also found that after the computer reboots it'll take 1-2 hours before it starts checking in with the JSS again (and then since it hadn't registered the policy has run it'll run again and not register it's run, then after restarting won't check-in for 1-2 hours...and on and on). Adding in the timeout/delay makes it so that won't happen.