From owner-freebsd-questions Sun Sep 22 12:20:22 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CE2F137B401; Sun, 22 Sep 2002 12:20:19 -0700 (PDT) Received: from posti.pp.htv.fi (posti.pp.htv.fi [212.90.64.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5D33C43E6E; Sun, 22 Sep 2002 12:20:18 -0700 (PDT) (envelope-from Petri.Riihikallio@Metis.fi) Received: from [192.168.0.2] ([212.90.71.47]) by posti.pp.htv.fi (8.11.1/8.11.1) with ESMTP id g8MJKFU29683; Sun, 22 Sep 2002 22:20:16 +0300 (EETDST) Mime-Version: 1.0 X-Sender: metis@pop.clinet.fi Message-Id: Date: Sun, 22 Sep 2002 22:20:12 +0300 To: freebsd-questions@FreeBSD.ORG, DougB@FreeBSD.ORG From: Petri Riihikallio Subject: How to shut down cleanly by killing power Content-Type: text/plain; charset="us-ascii" ; format="flowed" Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hello I have a FreeBSD 4.6.2 box and an UPS. I have chosen NUT (http://www.exploits.org/nut) as my UPS monitor. Everything compiles and runs fine. I have a problem with the shutdown script. How do I shut down the system properly? The problem is that I want to issue the command "upsdrvctl shutdown", which switches off the power from the UPS. What do I need to do before that? To be more specific. I have put a script like this in my /usr/local/etc/rc.d -------------------------/usr/local/etc/rc.d/znut.sh: #! /bin/sh case $1 in start) su nut -c /usr/local/libexec/upsdrvctl start su nut -c /usr/local/sbin/upsd /usr/local/upsmon ;; stop) if (test -f /etc/killpower) then echo "Killing the power, bye!" /bin/sync ### what to do here ? /usr/local/bin/upsdrvctl shutdown ### never makes it this far else killall upsmon killall upsd /usr/local/libexec/upsdrvctl stop fi ;; *) echo "Usage: $0: [ start | stop ]" 2>&1 exit 65 ;; esac --------------------------------------------------- I have called it znut.sh, so it should run last after all other shutdown scripts. (Nothing else runs after it in a powerfail situation ;-) Can I rely on alphabetical ordering? When the AC power is down and the UPS is almost exhausted, NUT creates a file "/etc/killpower" and starts system shutdown with "shutdown -h now". Init then runs all scripts in /usr/local/etc/rc.d with argument "stop". When the script finds the "/etc/killpower" file it syncs the disks and switches the UPS off. This is necessary, since the power might return when the system is in the "Press any key to reboot"-state. Then it would wait for the keypress indefinitely. NUT can't use "shutdown -r now", since the system might start a reboot while the UPS still supplies power. NUT can't use "shutdown -p now", since if the power is restored before the UPS runs dry, the system won't boot automatically. The "upsdrvctl shutdown" avoids these deadlocks by killing power at the UPS. When the AC power returns, the UPS first recharges, then it starts supplying power and my BIOS is set up to boot when power returns. My problem is that the disks aren't clean. If I put "umount -a" after the sync, I can't run the upsdrvctl from /usr. Should I remount /usr read-only? Or should I move the NUT programs to /bin and "umount -A". This would leave root dirty. I have read man pages for mount and umount. Both provide the -f flag, but warn against using it. Could I make use of it? The "sync" man page tells that halt is better since it does more than just a sync. Can I emulate these functions of halt from a script? What happens after the rc.shutdown? Are there any other housekeeping tasks after user scripts? I couldn't find any docs on that. -- 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