Petri Riihikallio <[EMAIL PROTECTED]> 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 [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message

Reply via email to