From owner-freebsd-questions Fri Sep 27 5:55:59 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 39BB137B401 for ; Fri, 27 Sep 2002 05:55:57 -0700 (PDT) Received: from lurza.secnetix.de (lurza.secnetix.de [212.66.1.130]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4436C43E65 for ; Fri, 27 Sep 2002 05:55:56 -0700 (PDT) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (localhost [IPv6:::1]) by lurza.secnetix.de (8.12.5/8.12.5) with ESMTP id g8RCtsmC037215 for ; Fri, 27 Sep 2002 14:55:55 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.12.5/8.12.5/Submit) id g8RCtsFK037214; Fri, 27 Sep 2002 14:55:54 +0200 (CEST) Date: Fri, 27 Sep 2002 14:55:54 +0200 (CEST) Message-Id: <200209271255.g8RCtsFK037214@lurza.secnetix.de> From: Oliver Fromme To: freebsd-questions@FreeBSD.ORG Reply-To: freebsd-questions@FreeBSD.ORG Subject: Re: How to shut down cleanly by killing power In-Reply-To: X-Newsgroups: list.freebsd-questions User-Agent: tin/1.5.4-20000523 ("1959") (UNIX) (FreeBSD/4.6-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit 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 Petri Riihikallio wrote: > 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? > [...] > stop) > if (test -f /etc/killpower) then > echo "Killing the power, bye!" > /bin/sync "sync" is pretty much useless, it doesn't buy you anything. Particularly, it won't mark your filesystems clean (so fsck will still have to run on the next boot), and it does not guarantee that there's no unwritten data left in memory. > ### what to do here ? > /usr/local/bin/upsdrvctl shutdown > ### never makes it this far Oh yes, it will. When the upsdrvctl powers the UPS off, there are still at least several milliseconds of power left to do lots of things. :-) > 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? No. Upon shutdown, the scripts will be executed in reverse ASCII order. You should rather call it something like "%%%whatever". There's never a guarantee, however, that some clever port tries to install a "%%%%%%foo" script in order to get there first ... Apart from that, there can be multiple directories with start/stop scripts, which will all be visited in order. By default, /usr/X11R6/etc/rc.d is used, too. So, maybe the best thing is to add your script at the end of /etc/rc.shutdown directly. > When the script finds the "/etc/killpower" file it syncs the disks .. which is useless ... > My problem is that the disks aren't clean. Right. You have to unmount them, or remount read-only. > If I put "umount -a" after the sync, I can't run the upsdrvctl from > /usr. Should I remount /usr read-only? Yes, exactly. This should do: umount -f -A mount -u -o ro / mount -o ro /usr Or compile upsdrvctl as a static binary and copy it to your root file system, so you don't need /usr. BTW, you do not need sync. > 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? Yes, that should be save, because at that point the programs get killed anyway. > What happens after the rc.shutdown? Are there any other housekeeping > tasks after user scripts? I couldn't find any docs on that. That's documented in /usr/src/sbin/init/init.c. Regards Oliver -- Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München Any opinions expressed in this message may be personal to the author and may not necessarily reflect the opinions of secnetix in any way. "All that we see or seem is just a dream within a dream" (E. A. Poe) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message