Restart required reminder

mikethemac
New Contributor

Hi,

I'm going to be rolling out updates from our SUS using Casper and it's working great so far with my test group using the basic settings that the JSS provides. I've been asked to see if it's possible to implement a message to users every X minutes to remind them that a restart is required and to do so at their earliest opportunity. I know Casper can show a message and set in motion a restart timer, but we'd rather not force a restart but pester the users into doing one. My thinking at the moment is -

Set an every 30 trigger policy to run some form of script which would check the local machine to see if a restart is pending, if so, display a message to the user informing/reminding/pestering them to restart. If no restart is pending, then obviously do nothing.

Is this possible? Can any one provide any pointers on how I can put together such a script (very new to scripting so go easy)

Many thanks!

7 REPLIES 7

dpertschi
Valued Contributor

Mike, I don't have an answer for you, but I was hoping to see some lively discussion since I have exactly the same need. Most of my users rarely restart or logout and I don't want to force it and cause data loss.

I have this discussion bookmarked, and of most interest to me is Larkin's mention of using Growl to pester the users into a logout. Tom, could you elaborate? I've not used Growl before.
https://jamfnation.jamfsoftware.com/discussion.html?id=2594

Those of you using Munki, is user notification and interaction much better there?

mm2270
Legendary Contributor III

I'm almost certain this can be done with the use of the jamfHelper and some advanced scripting behind the scenes. I can't give you an exact idea of how this would work, but the jamfHelper help page shows that you can capture the result of a button pressed by the user to stdout.
So, if you throw up an alert that tells them they need to reboot and have two buttons, let's call them "Restart Now" and "Delay 30" just for the sake of this exercise, each button will have a number output when selected. That number can be captured and fed back into a script that will either do a reboot now (or in 1 minute for example) or just initiate another jamfHelper session to alert them at a specified time interval (like 30 minutes in your case)
If you combine it with options that jamfHelper,app provides, such as "-lockHUD" (no close button on window, so users are forced to 'click' a button) and "-timeout" (selects a default button after a certain time period if no-one clicks one) you can get pretty close I believe to what you're looking for.

To see more about what the jamfHelper can do, run this in Terminal-
sudo /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -help

The only piece I'm not very clear on is how to get the pop-up to actually schedule itself to happen again after, say, 30 minutes, if the user clicks the "Delay" button. I'm thinking it might necessitate the creation of a launchd launchagent, but I'm not sure yet.
This is something we may be embarking on where I am, so if we get something put together that works well, I will be sure to post back here, provided no-one has given you a definite answer by then.

in the meantime, if this hasn't been put into a feature request, I definitely think it needs to be, because we get asked by our Windows management team if Casper can do this, since products like SCCM, LANDesk and others can. Our answer is usually yes, but that we have to develop it. It would be really great to have this as a built in feature.

bentoms
Release Candidate Programs Tester

I've something in the works with iHook, LaunchAgents & Cached packages.

Basically mirrors the MS system.

BUT, it'll be a few weeks before I get back to it. I'll post once done.

mm2270
Legendary Contributor III

Just to follow up quickly, here is a simple script that pops up a jamfHelper window similar to how I described it above. This window would time out after 2 minutes and choose the default "Restart Now" button if no-one is sitting at the Mac. You could of course make it choose the Delay button instead if there was a concern about data loss. The script has to be run as root.

#!/bin/sh

TITLE="Restart required"
MSG="Software Updates have been installed on your Mac that require a restart.

You can choose to restart now, or delay this restart by 30 minutes by choosing the appropriate button in this message"
ICON="/System/Library/CoreServices/Software Update.app/Contents/Resources/Restart.tif"

/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "$TITLE" -description "$MSG" -icon "$ICON" -button1 "Restart Now" -button2 "Delay 30" -defaultButton 1 -lockHUD -timeout 120

If I click Delay, I get an output of "2" and clicking Restart Now or letting it time out give me an output of "0" I can then expand on the script by having additional lines that echo the last result (echo $?) and use it to make some additional actions happen.

As I don't have the rest worked out I can't post it here yet, but as I said, it is something we're looking at doing, so we may have something working soon for this. Hopefully this at least gets you on the right path and will get the discussion going.

leslie
Contributor II
Contributor II

Do prefer defaulting to the delay button to avert potential data loss. Might try the following to get a re-occuring pop up reminder.

#!/bin/sh

choice="2"
TITLE="Restart required"
MSG="Software Updates have been installed on your Mac that require a restart.

You can choose to restart now, or delay this restart by 30 minutes by choosing the appropriate button in this message"

while [ "$choice" -ne "0" ]
do

ICON="/System/Library/CoreServices/Software Update.app/Contents/Resources/Restart.tif"

/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "$TITLE" -description "$MSG" -icon "$ICON" -button1 "Restart Now" -button2 "Delay 30" -defaultButton 2 -lockHUD -timeout 120

choice=echo $?

if [ "$choice" -ne "0" ];then sleep 1800 fi

done

reboot

mm2270
Legendary Contributor III

Yes, that would probably work and I had thought about doing a sleep command like you're looking at. The only thing I don't like about that is the script never really exits, but sits in an idle state. If the user keeps clicking Delay the script will be running indefinitely. Its probably not a big deal, but I'd prefer to find a method that will exit but then activate again after the specified timeframe has elapsed. A savvy user may actually be able to locate the process in Activity Viewer and kill it, escaping out of the reboot required cycle.
I would also like to find some way to only allow up to N number of delays before it forces a reboot. Many Windows management applications can do this, and it would be nice to have that too. Otherwise you may have some folks who just keep clicking that Delay button like 20 times.
But that's just me. :)

I'm also looking at doing a "shutdown -r +2" or something like that to give the user about 2 minutes to close out of apps/documents before it kicks off the restart and adjusting the wording in the dialog to explain that.

And I agree defaulting to the Delay button is the better/safer method.

acdesigntech
Contributor II

You could always create a user agent that runs every 30 minutes. If the restart now button is selected, the daemon is deleted and restart proceeds, and if they delay button is clicked, the process quits and the daemon will launch again in 30 minutes...