UPS support in OS X is sort of lame - ?

Discussion in 'macOS' started by smithrh, Jul 19, 2012.

  1. smithrh macrumors 68020

    smithrh

    Joined:
    Feb 28, 2009
    #1
    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...
     
  2. meme1255, Jul 19, 2012
    Last edited: Jul 19, 2012

    meme1255 macrumors 6502

    Joined:
    Jul 15, 2012
    Location:
    Czech Republic
    #2
    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..
     
  3. smithrh, Jul 19, 2012
    Last edited: Jul 19, 2012

    smithrh thread starter macrumors 68020

    smithrh

    Joined:
    Feb 28, 2009
    #3
    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.
     
  4. meme1255 macrumors 6502

    Joined:
    Jul 15, 2012
    Location:
    Czech Republic
    #4
    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..
     
  5. smithrh thread starter macrumors 68020

    smithrh

    Joined:
    Feb 28, 2009
    #5
    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.
     
  6. meme1255 macrumors 6502

    Joined:
    Jul 15, 2012
    Location:
    Czech Republic
    #6
  7. smithrh thread starter macrumors 68020

    smithrh

    Joined:
    Feb 28, 2009
    #7
    Thanks. I would be nervous about loading any third-party SW for this though.

    For example, from the pmset man page:

    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.
     
  8. meme1255 macrumors 6502

    Joined:
    Jul 15, 2012
    Location:
    Czech Republic
    #8
    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: )
     
  9. smithrh thread starter macrumors 68020

    smithrh

    Joined:
    Feb 28, 2009
    #9
    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...
     
  10. meme1255, Jul 19, 2012
    Last edited: Jul 19, 2012

    meme1255 macrumors 6502

    Joined:
    Jul 15, 2012
    Location:
    Czech Republic
    #10
    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
     
  11. smithrh thread starter macrumors 68020

    smithrh

    Joined:
    Feb 28, 2009
    #11
    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.
     
  12. meme1255 macrumors 6502

    Joined:
    Jul 15, 2012
    Location:
    Czech Republic
    #12
    You can define what for what is sudo needed... in sudoers file, at least on Linux, I haven't needed that on OS X yet ;)

    I don't know how to make automator search for specific text string.. You'll have to use Apple script, in my opinion ;)

    ----------

    Try modify this !
    http://osxdaily.com/2012/03/14/remotely-sleep-mac/

    I think that it should work! ;)
     
  13. smithrh thread starter macrumors 68020

    smithrh

    Joined:
    Feb 28, 2009
    #13
    ...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.
     
  14. meme1255 macrumors 6502

    Joined:
    Jul 15, 2012
    Location:
    Czech Republic
    #14
    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 ;) )
     

Share This Page