Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Sep 2002 14:03:55 +0300
From:      Petri Riihikallio <Petri.Riihikallio@Metis.fi>
To:        questions@FreeBSD.ORG
Subject:   Re: How to shut down cleanly by killing power
Message-ID:  <a05111b06b9b9eb21dfa7@[192.168.0.2]>

next in thread | raw e-mail | index | archive | help
Thanks for your reply!

>Maybe the question wasn't the clearest?

The problem is hard to explain. The post should be short, but include 
all information. Apparently I was too terse.

>>It doesn't feel right to crash after the UPS has run dry. (I don't 
>>have a generator.) About the first thing I was tought about Unix 
>>system administration was: "Always shut down properly". That's why 
>>I bought the UPS.
>
>How could you crash after the UPS has run dry?  You say you are 
>using NUT, then NUT should be able to initiate a system shutdown 
>_before_ the UPS runs out of juice - check your timings, don't let 
>the system run for longer than you have the capacity for.
>
>Maybe you should do "shutdown -h now" to actually halt the system, 
>then when the UPS powers off everything is dead.  If the power comes 
>back on, the UPS recharges a bit and then powers up your system 
>normally.

The problem is: What happens if power never disappears?

The situation I am worried about goes like this:

1. The UPS is almost empty, and the monitoring system issues shutdown -p.
2. The system starts the shutdown sequence. It can take well over a 
minute. There is no way to stop it now.
3. Power returns before the UPS is completely empty.

Now the system has shut down, but power is continuously available. 
The system won't boot automatically, no matter what you have set up 
in BIOS, because the power never goes down. With shutdown -h the 
system waits for a keypress to reboot.

It is a timing issue. You need plenty of bad luck to see it happen. 
But that's why UPSes have a way of killing battery power. This 
guarantees at least a short break of power. When the power returns, 
the BIOS settings can start the system.

>How can you send a command to the UPS _after_ the system has powered down?

:-) It is a chicken/egg-problem. The system can't send commands after 
powerdown, but if I issue the powerdown from multi-user system, the 
power disappears immediately. That's why I need to issue the 
powerdown command at the very end of shutdown, as close to cpu_halt() 
as possible.

In Linux scripts for apcupsd there is a halt-script to be run after 
everything else. The interesting part kills all other processes 
except for init and itself, unmounts all disks and stops swapping. 
The system is effectively in single-user state when the power 
disappears.

In FreeBSD there is no killall5, but I could write a replacement. 
Swapping can't be stopped in FreeBSD, but that is the case for normal 
shutdown as well. I can't run the UPS-shutdown command from 
/usr/local/bin after unmounting disks, so should I copy the UPS 
software to /bin or remount /usr read-only ?

I believed somebody else (more competent than I) would have written 
the necessary scripts.

apcupsd/halt.sh for SuSe (snippet):

># Write to wtmp file before unmounting /var
>$command -w
>
>echo "Sending all processes the TERM signal..."
>killall5 -15
>
>if [ "$1" = "fast" ]; then
>	sleep 1
>else
>	sleep 5
>fi
>
>echo "Sending all processes the KILL signal..."
>killall5 -9
>
>echo "Turning off swap."
>sync ; sync
>swapoff -a
>
>echo "Unmounting file systems"
>umount -av
>
># See if this is a powerfail situation.
>if [ -f @PWRFAILDIR@/powerfail ]; then
>   echo "APCUPSD attempting to shutoff UPS power"
>   echo
>   @sysconfdir@/apccontrol killpower
>   echo
>fi

The FreeBSD scripts have nothing like this. They just issue a 
shutdown -h and hope for the UPS to drain :-)

I didn't discover this problem myself. It is documented in 
http://www.apcupsd.com/users_manual/shutdown.html ("automatic 
reboot") and http://www.exploits.org/nut/docs/1.0.0/shutdown.html 
("power race"). It is just that I haven't found any FreeBSD solution.

Did this clarify the problem at all?
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a05111b06b9b9eb21dfa7>