Mac OS X,  Mac OS X Server

Command Line Power Management

Power Management is handled using the pmset command line utility, which I covered in a very small part yesterday.  There’s a lot more than just waking on magic packets that you can do with pmset though.  For starters, let’s look at the original command we discussed:

pmset -a womp 1

The -a refers to which power setting appled to whether the change was being made to battery, when we’re plugged in, UPS based power or, as we selected, all.  The flags, which fall into the first positional parameter are:

  • -a – all
  • -b – battery
  • -c – wall charger
  • -u – UPS

The next parameter you’ll pass to the command is the option (argument) for that power setting that you would like to send.  Here, you can set the number of minutes before the display goes to sleep, the brightness at various power settings and other options that have a direct effect on power.  These include the following (no – required with their use and 0 or 1 is boolean):

  • acwake – wake when you get high voltage power, it’s a 0 or 1
  • autorestart – automatically restart when there’s been a power loss (in other words whenever the system is plugged in), use 0 or 1
  • disksleep – number of minutes before the disk spins down
  • displaysleep – number of minutes before the computers monitor (er, signal to the monitor) goes to sleep
  • dps – 0 or 1, allows the CPU speed to dynamically change with power
  • halfdim – other than being a nickname I deserve, this option is a 0 or 1 that controls whether the display goes to half brightness for the power setting in question
  • lessbright – same as above just not as much
  • lidwake – automatically wake the system when the lid is opened, can be a 0 or 1
  • powerbutton – allows the box to go to sleep if someone hits the power button.  If it’s disabled, (since it’s a 0 or 1 ) then the system will not go to sleep if someone hits the power button.  This doesn’t disable powering it down by holding down that same power button, btw
  • reduce – whether to reduce the CPU speeds, can be 0 or 1
  • ring – wakes if someone calls the modem (but since the modern laptops don’t have modems, likely not something you’ll be using), it’s an integer- so 0 or 1
  • sleep – number of minutes before the computer goes to sleep (but doesn’t spin down the disk)
  • sms – Very cool, controls whether you’re using the Sudden Motion Sensor to stop the disk heads from locking down when the system gets jarred (G force math is kewl) – it’s a boolean thing, either on or off
  • womp – explained yesterday  

In addition to these, you can also use pmset to get information with the -g flag.  Using -g alone will net you all of the available information and while there are other options to limit what it outputs I normally just use grep for that…

There are also a number of options for managing SafeSleep (maintain the system state in memory, argument is hibernatemode), UPS options (haltvalue for how much battery to trigger a shutdown and halfafter for when to spin the CPU to 50% of full).  If you’re trying to manage the system and you have a battery (such as a laptop plugged into a UPS) then the settings will not be respected…

Just like in the System Preference pane, you can also control when the system sleeps, wakes, powers on, shuts down as well.  This uses the type argument (options being sleep, wake, poweron and shutdown) in conjunction with using date, time, weekdays and owner to set specific options.  

There are also a few other options that you don’t have in the GUI (’cause most of these are there).  These include force, which doesn’t write settings to disk, touch which reads currently enforced settings from the disk, noidle, which prevents idle sleep (and just spins the disk down when it’s ready) and  sleepnow, which just straight up puts the system to sleep right then.  sleepnow is pretty useful when you’re troubleshooting why a system won’t go to sleep.

For the Xserve specifically there is also a Lights Out Management in the form of the IPMI toolkit from Intel.  You can use that to power systems on, power them off and perform a few other tasks.  This can be secured (and actually has to be secured) with a password, using Server Monitor.  You can then control state through Server Monitor, or more granularly (and more importantly routable) through Apple Remote Desktop.  Find out more about IPMI on this page over at Intel.com.