7

Is there a way to figure out from a script whether a Mac needs to reboot? A file, the presence or contents of which I could monitor perhaps?

I'm looking for an equivalent to the file /var/run/reboot-required found on my Ubuntu boxes. My use case would be to centrally monitor my servers (and perhaps laptops) using Puppet, collectd or… well, something.

6

Like Linux, OS X is designed not to require restarting. There is no system wide means to determine if a restart is required - or even requested by a process.

For situations where a restart is required, the process responsible for needing the restart is also responsible for organising the restart.

Tools that update OS X are most likely to request a restart.

softwareupdate

Take a look at the softwareupdate manual page for the most likely candidate to request a restart.

softwareupdate prints a message at the end of the updating process stating if a restart is required. The calling script or user is then responsible for restarting.

Delayed Updates

If an update requires a restart to be successfully and safely installed, OS X will delay the updating process. The update will wait until the next restart or shut down.

This approach allows updates to be downloaded as part of a schedule but not interrupt or interfere with running processes or active users.

Pending Updates

To see if an update is pending, check the contents of /Library/Updates/. This folder appears to contain property list files documenting packages and updates queued for installation.

You can use the tool defaults in your scripts to read plist files such as /Library/Updates/index.plist:

defaults read /Library/Updates/index.plist InstallAtLogout
  • Agreed. Yet, some system updates say awful, un-unixy things like You have installed one or more updates that requires that you restart your computer. Please restart immediately. And it's these i'd like to catch, remotely. – llaurén Mar 27 '15 at 10:57
  • Take a look inside the /Library/Updates/ folder. I suspect this is where pending updates are documented. – Graham Miln Mar 27 '15 at 11:09
  • I will. Sorry for my previous quick comment. Only the first paragraph of your answer had come through at that time. I can't though find any indication of softwareupdate being able to tell me i'll need to reboot a mac. Oddly, the manual page omits a rather nifty command to set the URL of a software catalog, to force using a local repo instead of the one on Apple's servers. – llaurén Mar 27 '15 at 11:18
  • 1
    @danielAzuelos nothing religious about it. the answerer simply said os x was designed not to require restarts. he didn't say it doesn't require restarts in practice. this answer indeed explains why os x has no mechanism to determine if the system requires a restart—it was designed to never need to. – ell Mar 27 '15 at 16:13
  • 1
    @danielAzuelos A lot of these things are actually possible, but the discussion of how to accomplish it is probably beyond the scope of this site :-) – nohillside Mar 28 '15 at 9:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .