2007-04-05 16:48:42 +05:30
|
|
|
#!/bin/sh
|
2007-11-14 20:52:04 +05:30
|
|
|
# Copyright 2007 Roy Marples
|
|
|
|
# All rights reserved
|
|
|
|
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
# SUCH DAMAGE.
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
. /etc/init.d/functions.sh
|
|
|
|
. "${RC_LIBDIR}"/sh/rc-functions.sh
|
2007-11-23 17:34:11 +05:30
|
|
|
[ -r /etc/rc.conf ] && . /etc/rc.conf
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# Support LiveCD foo
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -r /sbin/livecd-functions.sh ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
. /sbin/livecd-functions.sh
|
|
|
|
livecd_read_commandline
|
|
|
|
fi
|
|
|
|
|
|
|
|
stop_addon devfs
|
|
|
|
stop_addon udev
|
|
|
|
|
2007-05-31 04:00:54 +05:30
|
|
|
# Really kill things off before unmounting
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -x /sbin/killall5 ]; then
|
2007-05-31 04:00:54 +05:30
|
|
|
killall5 -15
|
|
|
|
killall5 -9
|
|
|
|
fi
|
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
# Flush all pending disk writes now
|
2007-11-23 17:34:11 +05:30
|
|
|
sync; sync
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# If we are in a VPS, we don't need anything below here, because
|
|
|
|
# 1) we don't need (and by default can't) umount anything (VServer) or
|
|
|
|
# 2) the host utils take care of all umounting stuff (OpenVZ)
|
2007-11-23 17:34:11 +05:30
|
|
|
if [ "${RC_SYS}" = "VPS" ]; then
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -e /etc/init.d/"$1".sh ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
. /etc/init.d/"$1".sh
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If $svcdir is still mounted, preserve it if we can
|
2007-11-28 15:36:13 +05:30
|
|
|
mnt=$(mountinfo --node "${RC_SVCDIR}")
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -n "${mnt}" -a -w "${RC_LIBDIR}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
f_opts="-m -c"
|
|
|
|
[ "${RC_UNAME}" = "Linux" ] && f_opts="-c"
|
2007-11-29 21:53:59 +05:30
|
|
|
if type fuser >/dev/null 2>&1; then
|
|
|
|
if [ -n "$(fuser ${f_opts} "${svcdir}" 2>/dev/null)" ]; then
|
|
|
|
fuser -k ${f_opts} "${svcdir}" >/dev/null 2>&1
|
|
|
|
sleep 2
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
2007-08-15 20:19:41 +05:30
|
|
|
cp -p "${RC_SVCDIR}"/deptree "${RC_SVCDIR}"/depconfig \
|
|
|
|
"${RC_SVCDIR}"/softlevel "${RC_SVCDIR}"/nettree \
|
2007-10-31 21:16:56 +05:30
|
|
|
"${RC_SVCDIR}"/rc.log \
|
2007-08-15 20:19:41 +05:30
|
|
|
"${RC_LIBDIR}" 2>/dev/null
|
2007-04-05 16:48:42 +05:30
|
|
|
umount "${RC_SVCDIR}"
|
|
|
|
rm -rf "${RC_SVCDIR}"/*
|
|
|
|
# Pipe errors to /dev/null as we may have future timestamps
|
2007-08-15 20:19:41 +05:30
|
|
|
cp -p "${RC_LIBDIR}"/deptree "${RC_LIBDIR}"/depconfig \
|
|
|
|
"${RC_LIBDIR}"/softlevel "${RC_LIBDIR}"/nettree \
|
2007-10-31 21:16:56 +05:30
|
|
|
"${RC_LIBDIR}"/rc.log \
|
2007-08-15 20:19:41 +05:30
|
|
|
"${RC_SVCDIR}" 2>/dev/null
|
|
|
|
rm -f "${RC_LIBDIR}"/deptree "${RC_LIBDIR}"/depconfig \
|
2007-10-31 21:16:56 +05:30
|
|
|
"${RC_LIBDIR}"/softlevel "${RC_LIBDIR}"/nettree \
|
|
|
|
"${RC_LIBDIR}"/rc.log
|
2007-04-05 16:48:42 +05:30
|
|
|
# Release the memory disk if we used it
|
|
|
|
case "${mnt}" in
|
2007-11-28 21:15:03 +05:30
|
|
|
"/dev/md"[0-9]*) mdconfig -d -u "${mnt#/dev/md*}";;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
unmounted=0
|
|
|
|
# Remount the remaining filesystems read-only
|
2007-05-11 14:27:47 +05:30
|
|
|
# Most BSD's don't need this as the kernel handles it nicely
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ "${RC_UNAME}" = "Linux" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
ebegin "Remounting remaining filesystems read-only"
|
|
|
|
# We need the do_unmount function
|
|
|
|
. "${RC_LIBDIR}"/sh/rc-mount.sh
|
|
|
|
eindent
|
2007-07-11 22:57:46 +05:30
|
|
|
fs=
|
2007-11-28 21:15:03 +05:30
|
|
|
for x in ${net_fs_list}; do
|
2007-07-11 22:57:46 +05:30
|
|
|
fs="${fs}${fs:+|}${x}"
|
|
|
|
done
|
|
|
|
[ -n "${fs}" ] && fs="^(${fs})$"
|
2007-10-09 21:03:05 +05:30
|
|
|
do_unmount "mount -n -o remount,ro" \
|
|
|
|
--skip-point-regex "^(/dev|/dev/.*|/proc|/proc/.*|/sys|/sys/.*)$" \
|
|
|
|
${fs:+--skip-fstype-regex} ${fs} --nonetdev
|
2007-04-05 16:48:42 +05:30
|
|
|
eoutdent
|
|
|
|
eend $?
|
|
|
|
unmounted=$?
|
|
|
|
fi
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ ${unmounted} -ne 0 ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
[ -x /sbin/sulogin ] && sulogin -t 10 /dev/console
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Load the final script - not needed on BSD so they should not exist
|
|
|
|
[ -e /etc/init.d/"$1".sh ] && . /etc/init.d/"$1".sh
|
|
|
|
|
|
|
|
# Always exit 0 here
|
|
|
|
exit 0
|
|
|
|
|
|
|
|
# vim: set ts=4 :
|