Install the apcupsd daemon.
http://packages.ubuntulinux.org/hoary/admin/apcupsd
Take a look at the /etc/inittab file. There are init actions that deal with different power actions.
From the inittab man page:
Code:
powerwait
The process will be executed when the power goes down. Init is usually informed about this by a process talking to a UPS connected to the
computer. Init will wait for the process to finish before continuing.
powerfail
As for powerwait, except that init does not wait for the process's completion.
powerokwait
This process will be executed as soon as init is informed (edit) that the power has been restored.
powerfailnow
This process will be executed when init is told that the battery of the external UPS is almost empty and the power is failing (provided
that the external UPS and the monitoring process are able to detect this condition).
From my /etc/inittab file:
Quote:
# what to do when power fails/returns
pf::powerwait:/etc/init.d/powerfail start
pn::powerfailnow:/etc/init.d/powerfail now
#pn::powerfail:/etc/init.d/powerfail now
po::powerokwait:/etc/init.d/powerfail stop
|
You may have a different service in place of powerfail, but your /etc/inittab will reflect that. The apcupsd service will monitor the ups. If the power fails, it will call "init pf". If the power comes back after a bit, it will call "init po". It the battery level is critically low, it will call "init pn".