[clug] Network UPS Tools - Graceful shutdown

George at Clug Clug at goproject.info
Sat Oct 25 06:25:19 MDT 2014


    HI,

I have been looking for information on how to gracefully shutdown the
Linux KVM hypervisor on loss of power, before turning off the UPS.

Much the the information I found is a retelling of the same script
(not much variety). 

As I am using RAID, I was interested in how to manage this as well.

It will be a while before I can implement any of this in testing, so
in the mean time I am interested if anyone has any comments or
additions on the below information?

========================================================================================
http://www.apcupsd.com/manual/manual.html
http://xpt.sourceforge.net/techdocs/nix/sysmng/sm08-ReadOnlyRootFileSystem/single/
http://subnets.ru/blog/wp-content/uploads/2008/07/apcupsd.pdf
http://users.on.net/~emerson/mythtv/mdk/halt
http://www.scn.rain.com/~neighorn/docs/apcupsd/install.html
http://sophie2.aero.jussieu.fr/distrib/Mandriva/10.0-com/i586/by-pkgid/7c01ed439da10ac64f88f9a561cb209a/files/31
https://github.com/Ownercz/SOC-Minecore/blob/master/UPS/Nastaven%C3%AD%20Apcupsd/null/killpower
http://www.tldp.org/HOWTO/Ext2fs-Undeletion-5.html
# mount -n -o ro,remount /
http://www.cryptic.me.uk/technical/linuxraid.html






As a final check that the 'make install' went well, you should check
your halt script (in /etc/rc.d on SUSE systems, and in
/etc/rc.d/init.d on Red Hat systems) to see that the appropriate lines
have been inserted in the correct place. Modification of the halt
script is important so that at the end of the shutdown procedure,
apcupsd will be called again to command the UPS to turn off the power.
This should only be done in a power failure situation as indicated by
the presence of the /etc/powerfail file, and is necessary if you want
your machine to automatically be restarted when the power returns. On
a Red Hat system, the lines containing the # ***apcupsd*** should be
inserted just before the final halt command:

# Remount read only anything that's left mounted.
#echo "Remounting remaining filesystems (if any) readonly"
mount | awk '/ext2/ { print $3 }' | while read line; do
    mount -n -o ro,remount $line
done

# See if this is a powerfail
situation.                              
# ***apcupsd***
if [ -f /etc/apcupsd/powerfail ];
then                                #
***apcupsd***
  
echo                                                              
# ***apcupsd***
   echo "APCUPSD will now power off the
UPS"                          # ***apcupsd***
  
echo                                                              
# ***apcupsd***
   /etc/apcupsd/apccontrol
killpower                                 
# ***apcupsd***
  
echo                                                              
# ***apcupsd***
   echo "Please ensure that the UPS has powered off before
rebooting" # ***apcupsd***
   echo "Otherwise, the UPS may cut the power during the
reboot!!!"   # ***apcupsd***
  
echo                                                              
# ***apcupsd***
fi                                                                   
# ***apcupsd***

# Now halt or reboot.
echo "$message"
if [ -f /fastboot ]; then
 echo "On the next boot fsck will be skipped."
elif [ -f /forcefsck ]; then
 echo "On the next boot fsck will be forced."
fi

The purpose of modifying the system halt files is so that apcupsd will
be recalled after the system is in a stable state. At that point,
apcupsd will instruct the UPS to shut off the power. This is necessary
if you wish your system to automatically reboot when the mains power
is restored. If you prefer to manually reboot your system, you can
skip this final system dependent installation step by specifying the
disable-install-distdir option on the './configure' command (see below
for more details).

------------------------------------------------------
https://github.com/ClusterLabs/resource-agents/blob/master/heartbeat/Raid1
# STOP: stop the RAID device
#
mark_readonly() {
local mddev=$1
local rc
ocf_log info "Attempting to mark array $mddev readonly"
$MDADM --readonly $mddev --config=$RAIDCONF
rc=$?
if [ $rc -ne 0 ]; then
ocf_log err "Failed to set $mddev readonly (rc=$rc)"
fi
return $rc
}

---------------------------------------------------
http://old.networkupstools.org/doc/1.4.1/shutdown.html
RAID warning
============

   NOTE: If you run any sort of RAID equipment, make sure your
arrays
   are either halted (if possible) or switched to "read-only" mode.
   Otherwise you may suffer a long resync once the system comes back
up.

   The kernel may not ever run its final shutdown procedure, so you
   must take care of all array shutdowns in userspace before
upsdrvctl
   runs.

   If you use software RAID (md) on Linux, get mdadm and try using
   'mdadm --readonly' to put your arrays in a safe state.  This has
to
   happen after your shutdown scripts have remounted the
filesystems.

   On hardware RAID or other kernels, you have to do some detective
work.
   It may be necessary to contact the vendor or the author of your
   driver to find out how to put the array in a state where a power
loss
   won't leave it "dirty".

   My understanding is that 3ware devices on Linux will be fine
unless
   there are pending writes.  Make sure your filesystems are
remounted
   read-only and you should be covered.

---------------------------------------------------


https://lists.fedoraproject.org/pipermail/users/2011-January/391646.html
http://ubuntuforums.org/archive/index.php/t-1417410.html
http://oss.sgi.com/archives/xfs/2001-06/msg02356.html
http://oss.sgi.com/archives/xfs/2013-02/msg00108.html
https://www.centos.org/forums/viewtopic.php?t=31977

========================================================================================


At Sunday, 24-08-2014 on 21:56 Craig Small wrote:


On Sun, Aug 24, 2014 at 12:30:41PM +1000, George at Clug wrote:
> Have you had experience in installing UPS for Linux ?  I would be
> interested in any information you may have on how to get NUT working
> with a UPS.  It seems that I may now be able to achieve this,
however
> finding complete installation instructions has not be easy. In fact
I
> have not been able find any.
I have an Eaton (3S 700 I think) on a Debian system. It's connected
using the usbhid driver and generally works fine.

Debian has rules to set the group access correctly, found in
/lib/udev/rules.d/52-nut-usbups.rules so its a matter of just using
the
standard boilerplate type configuration and away you go.
For example /etc/nut/ups.conf is just
[myups]
        driver = usbhid-ups
        port = auto
        desc = "Main UPS"

> The main issue I was experiencing is that the upsdrvctl was unable
to
> own the usb port into which the UPS was connected. 
I don't have such things, the udev rules in the nut-server package
does it for me.

ls -l /dev/bus/usb/009
total 0
crw-rw-r-- 1 root root 189, 1024 Jul 15 21:49 001
crw-rw-r-- 1 root nut  189, 1028 Aug 24 21:52 005

009:005 is the USB ID of the UPS.
This is with NUT version 2.7.2

- Craig
(You wouldn't believe the number of times I almost typed USP UBS)
-- 
Craig Small (@smallsees)   http://enc.com.au/       csmall at
: enc.com.au
Debian GNU/Linux           http://www.debian.org/   csmall
at : debian.org
GPG fingerprint:        5D2F B320 B825 D939 04D2  0519 3938
F96B DF50 FEA5
-- 
linux mailing list
linux at lists.samba.org
https://lists.samba.org/mailman/listinfo/linux




More information about the linux mailing list