Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Sep 1997 12:26:11 +0200
From:      j@uriah.heep.sax.de (J Wunsch)
To:        stable@freebsd.org
Cc:        current@freebsd.org
Subject:   Re: rc.shutdown [was: Another NFS bogon in 2.2-stable?]
Message-ID:  <19970921122611.AG59280@uriah.heep.sax.de>
References:  <199709210751.RAA24163@godzilla.zeta.org.au>

next in thread | previous in thread | raw e-mail | index | archive | help
As Bruce Evans wrote:

> >Did anybody else notice that shutting down a 2.2-stable machine that
> >has NFS file systems mounted never yields a clean shutdown?  My 2.2
> 
> I notice it in -current for a nfs-mounted /usr.  It is caused by
> some daemons holding nfs files open and taking too long to die.
> I use `umount -Af -t nfs' before rebooting.  This tends to kill
> the daemons early when their fd's go away.

(Since you confirm it for -current, too, i've moved the discussion
there.  Please respect the reply-to.)

In my case, it's probably the daemons running off the NFS-mounted
/usr/local then.

Should we ship an /etc/rc.shutdown by default, that kills off the
daemons and unmounts NFS file systems?  At least daemons that properly
recorded their PID in /var/run/*pid could be killed easily.

The following looks like a pretty good default rc.shutdown to me.  The
idea behind it is also that you can shutdown to single-user, and get
an as clean as possible environment.  (I didn't make up my mind about
non-NFS filesystems, however.  This might cause some LKMs to remain
busy.)

The mess to umount NFS filesystems could be replaced by `umount -Af -t
nfs' in -current, but the -A option isn't available yet in 2.2-stable.
Does -A correctly handle /etc/fstab reverse order, IOW, would it work
if e.g. both /usr, and /usr/local were NFS-mounted?

For some unknown reason, this script isn't really run on my 2.2 test
machine when doing a `shutdown -h/-r', albeit it is run when doing a
plain shutdown to single-user, as well as when typing Ctrl-Alt-Del.
Looks like intention, but is IMHO bogus.  If i type `shutdown -r', i
expect it do perform a clean reboot.  (This is the only way to do it
when not sitting on the physical console.)

Would anybody mind me committing the following script?

#!/bin/sh

stty status '^T'

HOME=/; export HOME
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
export PATH

echo -n "Stopping system daemons:"
#
# Stop by reverse PID order.  Not ideal.
for file in /var/run/*.pid; do
	if [ "$file" = "/var/run/*.pid" ]; then
		break
	fi
	pid=$(head -1 "$file")	# sendmail needs head -1
	name=$(expr "$file" : '/var/run/\(.*\)\.pid')
	pidlist="$pidlist$pid $name
"
done
echo "$pidlist" | sort -n -r | while read pid name; do
	if [ "$pid" = "" ]; then
		break
	fi
	echo -n " $name"
	kill -TERM $pid && rm -f /var/run/$name.pid
done
echo '.'

echo -n "Unloading kernel modules:"
modstat | (
	read junk	# headline
	while read type id off loadaddr size info rev name; do
		echo -n " $name"
		modunload -i $id
	done
)
echo '.'

echo -n "Unmounting NFS filesystems:"
nfslist=$(
	mount -t nfs | while read resource on mntpoint junk; do
		echo "$resource $mntpoint"
	done
)
echo "$nfslist" | while read resource mntpoint; do
	if [ "$mntpoint" = ""]; then
		break
	fi
	echo -n " $resource"
	umount -f "$mntpoint"
done
echo '.'

echo -n "Bringing down network interfaces:"
ifconfig -a | while read line; do
	if iface=$(expr "$line" : '\([a-z][a-z]*[0-9][0-9]*\):'); then
		echo -n " $iface"
		ifconfig $iface down
		ifface="$iface"
	fi
	if ipaddr=$(expr "$line" : ' *inet \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)'
	then
		echo -n " $ipaddr"
		ifconfig $ifface $ipaddr delete
	fi
done
echo '.'

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



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