SuSE Linux: Versions since 7.2
Starting from version 0.44.3 of the smartups package (included in SuSE Linux version 7.2), it is possible to trigger a so-called forced shutdown that additionally notifies any existing slave systems about the power failure and shuts them down if necessary. The desired effect can be achieved in combination with a timer that starts when a power failure occurs.
The following procedure describes the configuration of the master host (being connected directly to the UPS); slave systems are not taken into consideration in this configuration.
/etc/ups/upsmon.conf
.
Search for the following lines:
# NOTIFYCMD /usr/local/ups/bin/notifyme # NOTIFYFLAG ONLINE SYSLOG # NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
and modify them as follows:
NOTIFYCMD /usr/sbin/upssched NOTIFYFLAG ONLINE SYSLOG+EXEC NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
This makes sure the command /usr/sbin/upssched
is executed when
a power failure occurs (ONBATT) and the power returns (ONLINE).
The command /usr/sbin/upssched
starts a timer that executes a command (or script)
after a specified period or stops the timer if necessary. This information is contained in the
configuration file /etc/ups/upssched.conf
which you can create
with an editor of your choice.
Here a sample file that you can directly adopt with cut & paste:
# # /etc/ups/upssched.conf # Configuration file for /usr/sbin/upssched # CMDSCRIPT /usr/local/sbin/go-down PIPEFN /var/run/upssched.pipe AT ONBATT * START-TIMER onbattwarn 60 AT ONLINE * CANCEL-TIMER onbattwarn
This configuration causes a 60-second timer to be started whenever a power failure triggers /usr/sbin/upssched
(ONBATT);
upon termination of the specified 60 seconds, the script indicated in the line CMDSCRIPT is launched (in this example
/usr/local/sbin/go-down
).
In case the power returns before the timer period runs out (ONLINE), the timer stops.
Use an editor to create the file /usr/local/sbin/go-down
with the following content:
#!/bin/bash # # /usr/local/sbin/go-down # Script for shutting down the computer # upsmon -c fsd
Then use the command
chmod 700 /usr/local/sbin/go-down
to change the access permissions of this file.
At the command line, enter
rcups restart
to restart the UPS service and detach the power line of the UPS. Wait until the following message appears on the console:
Broadcast Message from root@D222 (somewhere) at 15:18 ... UPS localhost on battery
Then plug in the cable. Now enter the command
tail -n20 /var/log/messages
to check if the timer was started/stopped correctly, in which case the output should look as follows:
Jul 10 15:18:34 D222 upsmon[3437]: UPS localhost on battery Jul 10 15:18:34 D222 upssched[3445]: Timer daemon running Jul 10 15:18:34 D222 upssched[3445]: New timer: onbattwarn (60 seconds) Jul 10 15:19:05 D222 upsmon[3437]: UPS localhost on line power Jul 10 15:19:05 D222 upssched[3445]: Cancelling timer: onbattwarn Jul 10 15:19:05 D222 upssched[3445]: Timer queue empty, exiting
If the test was successful, detach the power line of the UPS once more. The computer will shut down automatically after one minute.
If you want the UPS to shut down too after this procedure, an additional command must be sent to the UPS during
the shutdown. For this purpose, you can modify the script /etc/init.d/halt.local
as described below.
/usr/local/sbin/ups-down
with the following content:
#!/bin/bash # # /usr/local/sbin/ups-down # Script for shutting down the UPS in the event of a power failure # if (test -f /etc/killpower) then echo "Killing the power, bye!" /usr/lib/ups/driver/apcsmart -k /dev/ttyS0 fi
Then use the command
chmod 700 /usr/local/sbin/ups-down
to change the access permissions of this file.
Now make sure this script is executed by the file /etc/init.d/halt.local
.
The command
echo "/usr/local/sbin/ups-down" >>/etc/init.d/halt.local
will do this for you.
At system shutdown, the script looks for the file /etc/killpower
. This file is
generated by the UPS software when you give the computer the signal to shut down. In case
this file exists, the command /usr/lib/ups/driver/apcsmart -k /dev/ttyS0
is issued and prompts the UPS to shutdown automatically after a period which is
predefined in the UPS.
As soon as the power returns, the UPS turns on automatically and starts the computer. ATX systems sometimes require a corresponding BIOS setting in order to retain this functionality.
SDB-tsieden_smartups-shutdown
)