From owner-freebsd-questions Thu Sep 26 19: 9: 8 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 CCD6537B401 for ; Thu, 26 Sep 2002 19:09:04 -0700 (PDT) Received: from mta02.mail.mel.aone.net.au (mta02.mail.au.uu.net [203.2.192.82]) by mx1.FreeBSD.org (Postfix) with ESMTP id BB13A43E3B for ; Thu, 26 Sep 2002 19:09:03 -0700 (PDT) (envelope-from rbyrnes@ozemail.com.au) Received: from ausyddtp0050.ozemail.com.au ([203.166.67.234]) by mta02.mail.mel.aone.net.au with ESMTP id <20020927020902.GEVP6230.mta02.mail.mel.aone.net.au@ausyddtp0050.ozemail.com.au>; Fri, 27 Sep 2002 12:09:02 +1000 Message-Id: <5.1.0.14.2.20020927120155.01d4cd90@pop.ozemail.com.au> X-Sender: rbyrnes@pop.ozemail.com.au X-Mailer: I wish it was Linux Date: Fri, 27 Sep 2002 12:08:26 +1000 To: Petri Riihikallio From: Rob B Subject: Re: How to shut down cleanly by killing power Cc: freebsd-questions@FreeBSD.ORG In-Reply-To: Mime-Version: 1.0 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 At 17:02 26/09/2002 +0300, Petri Riihikallio sent this up the stick: >A couple of days ago I sent a message asking how to shut down a FreeBSD >system when I KNOW the power will be off after the next script command. > >Nobody has commented yet. Maybe the question wasn't the clearest? >Am I the only one using an UPS with FreeBSD? Not at all >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. How can you send a command to the UPS _after_ the system has powered down? Why tell the UPS to shutdown - your UPS should be able to turn itself off when it runs out of battery. 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. Or maybe I can't understand what you are trying to do Cheers, Rob >At 22:20 +0300 22.9.2002, Petri Riihikallio wrote: >>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. No problems with NUT. 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: 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". 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 the script 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 my 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. > >-- >The only number that is both even and odd is infinity. > >This is random quote 1025 of a collection of 1253 >[15200.8 km (8207.8 mi), 262.8 deg](Apparent) Rennerian To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message