Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

smithrh

macrumors 68030
Original poster
Feb 28, 2009
2,747
1,792
I've had my server on a UPS for years and I've always liked the integration that OS X has with the UPS.

However, with the storm season (and a few outages), I realized I needed to cover my iMac as well as I'm starting to use it extensively for critical business needs - it was pretty much personal use before then.

My point is this - sure, you can configure what the Mac does and when it does it with the UPS. But the thing that blows is that the only thing that it does is what looks to be the equivalent of fastshutdown. Anything that you had open is gone.

Oh, I'm sorry, did you step away for 10 minutes and forget to save, and there was a power failure while you were away? SOL. Did the power go out overnight when you were sleeping? SOL.

Really?

Contrast this to my MacBook. When it senses that it's not plugged in any more, it will hibernate. The entire state of the machine is saved, and while it takes a minute or so to re-load, once it does, you're back to where you were.

Is there any reason that this isn't available for desktops?

Or am I missing something in how the OS treats the UPS, and I could get what I want from what's there today? (Again, in the OS)

Inquiring minds want to know...
 
  • Like
Reactions: dysamoria
There must be some option in terminal to change that.. I'll try to find it ;) ( If you could tell me your UPS type, I might help you more)

Edit: Looks like it is not here ( :mad: )

Terminal says:

UPS SPECIFIC ARGUMENTS
UPS-specific arguments are only valid following the -u option. UPS settings also have an on/off value. Use a -1 argument instead of percent or minutes to turn any of these settings off. If multiple halt conditions are specified, the
system will halt on the first condition that occurs in a low power situation.

haltlevel - when draining UPS battery, battery level at which to trigger an emergency shutdown (value in %)
haltafter - when draining UPS battery, trigger emergency shutdown after this long running on UPS power (value in minutes, or 0 to disable)
haltremain - when draining UPS battery, trigger emergency shutdown when this much time remaining on UPS power is estimated (value in minutes, or 0 to disable)

Note: None of these settings are observed on a system with support for an internal battery, such as a laptop. UPS emergency shutdown settings are for desktop and server only.


But maybe possible to get level of UPS charge level and make a script which hibernates Mac when power level is below defined percentage..
 
Last edited:
Exactly my point... it's not there.

Thanks for looking, I appreciate the effort!

Can you even force a "hibernate" on a non-laptop model?

Edited to add:

I would like to be able to hibernate my iMac (e.g., a non-laptop/non-internal battery model) instead of fastshutdown once the UPS shutdown threshold(s) are reached.

I am using APC, but this should really be applicable to all UPSs. It shouldn't be model- or manufacturer-specific.
 
Last edited:
Hibernate can be done through pmset sleepnow - depends on set hibernate mode - pmset -g | grep hibernate mode :

0 - Old style sleep mode, with RAM powered on while sleeping, safe sleep disabled, and super-fast wake.
1 - Hibernation mode, with RAM contents written to disk, system totally shut down while “sleeping,” and slower wake up, due to reading the contents of RAM off the hard drive.
3 - The default mode on machines introduced since about fall 2005. RAM is powered on while sleeping, but RAM contents are also written to disk before sleeping. In the event of total power loss, the system enters hibernation mode automatically.
5 - This is the same as mode 1, but it’s for those using secure virtual memory (in System Preferences -> Security).
7 - This is the same as mode 3, but it’s for those using secure virtual memory.


Then shutdown -s / pmset sleepnow and your Mac is being hibernated.

I'll try to make some script.. But as I don't have UPS, I can't use UPS options..
 
Excellent... I had worried that perhaps the option to hibernate was taken away from desktops by fiat.

By the way, another thing that Apple is weak at in this area is WARNING people that it's about to shut down. First time I was testing my UPS (always a wise thing to do), I had thought I was still a few minutes away from a shutdown (looks more like a halt now, even worse) - but no, boom, down it went.

No warning, no nothing. Is it really that hard to give 30 seconds of warning to the poor soul behind the keyboard?

When you're having power issues and working on something critical, you're vulnerable. This is where a computer maker that also develops the OS can shine, by helping you when you need it most.
 
Thanks. I would be nervous about loading any third-party SW for this though.

For example, from the pmset man page:

We do not recommend modifying hibernation settings. Any changes you make are not supported. If you choose to do so anyway, we recommend using one of these three settings. For your sake and mine, please don't use anything other 0, 3, or 25.

I don't see how APC would work around this any better than I could.

It is interesting that there is a "sleepimage" file on my iMac, and it's recent, and it's big (I have 16Gb RAM). So at some point mode 3 was invoked - somehow.
 
On friend's iMac, switched from 0 to 3 mode without problem ..

And the problem with "sudo halt" type shutdown - as usual, (nearly) no one cares :mad::eek:

I think that log from console when running on UPS might help me, but i dont think so.. ( I dont know where are UPS- shutdown settings saved - maybe manually rewriting them to shutdown -s would be possible :confused: )
 
Have a look at the "GETTING" section of the pmset man page... there's a lot more options than I remember a year or two (or more) ago...

pmset -g log

is pretty interesting.

I could envision a crontab job running every minute or so, detecting if running on UPS power ( 'pmset -g | grep "UPS Power" | grep \*' ), then setting the hibernate mode to "safe sleep", then forcing a sleep (hibernate) after a minute or so.

* The trick would be to set the Mac OS X UPS settings so the crontab would find UPS power activity before the OS did the shutdown/halt

* Not sure how to force a sleep from the command line...

Edit - dang, missed "sleepnow" option... this is coming together...
 
That is what is meant, but i don't know how to exactly do that ;)

If you figure this out - please post it here ! ;)


I think this is possible over Automator / Applescript + bash scripts ;]

Maybe something like : "if ("UPS power is detected by "pmset -g | grep UPS power" "),{
shutdown -s};

:D
 
Last edited:
I will - I need to see what needs to run as root and what can be executed at the user level - plus I need to get up to speed on the newfangled replacement for cron jobs...


As an example,

pmset sleepnow

Can be executed as a non-root user and it works.
 
...I have to get back to work, but I have a solid idea of what to do at this point.

Hopefully I can post something this weekend.

Apple: c'mon now. This should be in the OS. You do it perfectly on laptops - no excuse not to deploy it on desktops too.
 
There are more things that SHOULD be in :apple: OS but they are not..
( for example, capability to show CPU frequency in real-time, you can't set Voltage &*Frequency of CPU under Lion (I think that at least terminal possibility for power users should be here.., other people will find many more ;) )
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.