How to keep Macs from sleeping while installing OS?

znilsson
Contributor II

This may be a stupid question because the act of installing the OS seems like it would prevent the Mac from sleeping in the first place, but because it's being done in the background for a cached installer (via self service) is it possible for the Mac to sleep while it's running?

I only ask because a couple times now, a Yosemite install from self service has failed because of a communication error, (request timed out) and that's typically caused by a Mac going to sleep which cuts the network connection. Of course it could be caused by something else but since these installs are being done remotely I can't watch them to see what's going on.

If the background install prevents sleep then sleep obviously isn't the problem, but I don't know what else would be causing a request time out that prevents the install from going forward. Anyway my question was regarding a way to keep the Mac awake while the install is going on, and I found that

caffeinate -s

works to keep the Mac awake, and

killall caffeinate

works to stop the process so it can go back to its normal sleep parameters. So I was wondering how to start caffeine, make sure that process stays running during the install process, and then kill it when the install is done. My thought was to set caffeine -s in Execute Command in Files & Processes in my Yosemite install policy, and then in the same policy add a "killall caffeine" script set to run After.

Even if none of this is applicable to my situation because it wouldn't be going to sleep while installing the OS in the background anyway, I'd still like to know if this would work because I don't understand the timing of the execute process command vs. running the kill script set to "after".

Like, even if the execute command runs right up front, at what point does the kill script run, when it's set to "after"? Like right after the execute command? Or does "after" mean after the install is finished and it's the last thing that runs before rebooting?

Thanks for whatever insight anybody has.

6 REPLIES 6

mm2270
Legendary Contributor III

I always get a little confused about this stuff myself, but I do believe that anything in the Run command runs after anything from the policy, such as any scripts, but before the Inventory collection if that's enabled.
If I'm right, you would want to change the setup. Have a Before script called that enables caffeinate, then either an After script to kill it or just put the kill in the Run command field. Your OS installation would be in the middle of those two items in terms of the order.

OTOH, if you're using any kind of scripted installation process rather than built in functions, you could just include enabling and disabling of caffeinate in the script itself. It sounds like you're using the built in install cached function perhaps though.

Lastly, I'm actually not sure if a background installation will allow the Mac to sleep. It might though since its not a GUI process. You would think the OS itself wouldn't actually allow that to happen, but I just don't know for sure.

gregneagle
Valued Contributor

The OS installer disables idle sleep during installation:

Jan 22 16:52:40 MacBook-Air.local OSInstaller[402]: Disabling system idle sleep.

But that doesn't affect the download and caching of the installer before the actual installation takes place (that would be JAMF code running) and it doesn't prevent sleep by other methods (like closing the lid of a laptop, or battery getting low).

znilsson
Contributor II

Ah ok - so I'm just catching up to what Apple's engineers figured out a long time ago. :D But would you say it might be worth it to run the caffeine before and after scripts on my yosemite installer caching policy, just as a precaution to prevent potential data corruption? Of course there's nothing we can do about somebody closing the lid, but maybe in the context of "every little bit helps"?

bentoms
Release Candidate Programs Tester

@znilsson, if you cache over HTTP/S then he downloads are resumable.. So shouldn't matter.

znilsson
Contributor II

Ah, our JSS is on a Windows 2008 VM and we're actually using SMB. Of course that could also explain the seemingly random communication issues, but it's not a problem most of the time at least.

Kaltsas
Contributor III

Threadjacking but I have been playing with caffeinate and I swear this was working before I upgraded to 9.62 I had scripts that invoked caffeinate & as a before script and killall caffeinate as an after script on a few larger policies but now when it is kicked off from self service it hangs on the caffeinate script. Thoughts on the syntax?