2021-04-23 21:13:09 +02:00
|
|
|
#!/bin/bash
|
2009-08-26 17:00:38 +02:00
|
|
|
#
|
|
|
|
# rc.K This file is executed by init when it goes into runlevel
|
|
|
|
# 1, which is the administrative state. It kills all
|
|
|
|
# daemons and then puts the system into single user mode.
|
|
|
|
# Note that the file systems are kept mounted.
|
|
|
|
#
|
|
|
|
# Version: @(#)/etc/rc.d/rc.K 3.1415 Sat Jan 13 13:37:26 PST 2001
|
|
|
|
#
|
|
|
|
# Author: Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org>
|
|
|
|
# Modified by: Patrick J. Volkerding <volkerdi@slackware.com>
|
|
|
|
#
|
|
|
|
|
|
|
|
# Set the path.
|
2018-05-28 21:12:29 +02:00
|
|
|
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
|
2009-08-26 17:00:38 +02:00
|
|
|
|
2020-01-13 20:18:02 +01:00
|
|
|
# Load a custom screen font if the user has an rc.font script.
|
|
|
|
if [ -x /etc/rc.d/rc.font ]; then
|
|
|
|
/etc/rc.d/rc.font
|
|
|
|
fi
|
|
|
|
|
2009-08-26 17:00:38 +02:00
|
|
|
# Load any needed keyboard mappings:
|
|
|
|
if [ -x /etc/rc.d/rc.keymap ]; then
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.keymap
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If there are SystemV init scripts for this runlevel, run them.
|
|
|
|
if [ -x /etc/rc.d/rc.sysvinit ]; then
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.sysvinit
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Try to turn off quota:
|
|
|
|
if grep -q quota /etc/fstab ; then
|
|
|
|
if [ -x /sbin/quotaoff ]; then
|
|
|
|
echo "Turning off filesystem quotas."
|
|
|
|
/sbin/quotaoff -a
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Try to turn off accounting:
|
|
|
|
if [ -x /sbin/accton -a -r /var/log/pacct ]; then
|
|
|
|
/sbin/accton off
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Run any local shutdown scripts:
|
|
|
|
if [ -x /etc/rc.d/rc.local_shutdown ]; then
|
|
|
|
/etc/rc.d/rc.local_shutdown stop
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Stop the Apache web server:
|
|
|
|
if [ -x /etc/rc.d/rc.httpd ]; then
|
|
|
|
/etc/rc.d/rc.httpd stop
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Stop the Samba server:
|
|
|
|
if [ -x /etc/rc.d/rc.samba ]; then
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.samba stop
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Shut down the NFS server:
|
|
|
|
if [ -x /etc/rc.d/rc.nfsd ]; then
|
|
|
|
/etc/rc.d/rc.nfsd stop
|
|
|
|
fi
|
|
|
|
|
2011-04-25 15:37:00 +02:00
|
|
|
# Kill any processes (typically gam) that would otherwise prevent
|
|
|
|
# unmounting NFS volumes:
|
|
|
|
unset FUSER_DELAY
|
2019-08-28 23:29:41 +02:00
|
|
|
for dir in $(/bin/mount | grep -e 'type nfs ' -e 'type nfs4 ' | sed -e 's|.* on ||g' | cut -d ' ' -f 1) ; do
|
2011-04-25 15:37:00 +02:00
|
|
|
echo "Killing processes holding NFS mount $dir open..."
|
|
|
|
# Background this to prevent fuser from also blocking shutdown:
|
2018-07-25 05:50:17 +02:00
|
|
|
/usr/bin/fuser -k -M -m "$dir" &
|
2011-04-25 15:37:00 +02:00
|
|
|
FUSER_DELAY=5
|
|
|
|
done
|
|
|
|
# If fuser was run, let it have some delay:
|
|
|
|
if [ ! -z "$FUSER_DELAY" ]; then
|
|
|
|
sleep $FUSER_DELAY
|
|
|
|
fi
|
|
|
|
|
2009-08-26 17:00:38 +02:00
|
|
|
# Unmount any NFS, SMB, or CIFS filesystems:
|
2016-06-30 22:26:57 +02:00
|
|
|
echo "Unmounting remote filesystems:"
|
2019-08-28 23:29:41 +02:00
|
|
|
/bin/umount -v -a -l -f -r -t nfs,nfs4,smbfs,cifs | tr -d ' ' | grep successfully | sed "s/:successfullyunmounted/ has been successfully unmounted./g"
|
2009-08-26 17:00:38 +02:00
|
|
|
|
|
|
|
# Shut down PCMCIA devices:
|
|
|
|
if [ -x /etc/rc.d/rc.pcmcia ] ; then
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.pcmcia stop
|
2009-08-26 17:00:38 +02:00
|
|
|
# The cards might need a little extra time here to deactivate:
|
|
|
|
sleep 5
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Terminate acpid before syslog:
|
|
|
|
if [ -x /etc/rc.d/rc.acpid -a -r /var/run/acpid.pid ]; then # quit
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.acpid stop
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Kill all processes.
|
2016-06-30 22:26:57 +02:00
|
|
|
OMITPIDS="$(for p in $(pgrep mdmon); do echo -o $p; done)" # Don't kill mdmon
|
2009-08-26 17:00:38 +02:00
|
|
|
echo
|
|
|
|
echo "Sending all processes the SIGHUP signal."
|
2016-06-30 22:26:57 +02:00
|
|
|
killall5 -1 $OMITPIDS
|
2009-08-26 17:00:38 +02:00
|
|
|
echo -n "Waiting for processes to hang up"
|
|
|
|
for loop in 0 1 2 3 4 5 ; do
|
|
|
|
sleep 1
|
|
|
|
echo -n "."
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
echo "Sending all processes the SIGTERM signal."
|
2016-06-30 22:26:57 +02:00
|
|
|
killall5 -15 $OMITPIDS
|
2009-08-26 17:00:38 +02:00
|
|
|
echo -n "Waiting for processes to terminate"
|
|
|
|
for loop in 0 1 2 3 4 5 ; do
|
|
|
|
sleep 1
|
|
|
|
echo -n "."
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
echo "Sending all processes the SIGKILL signal."
|
2016-06-30 22:26:57 +02:00
|
|
|
killall5 -9 $OMITPIDS
|
2009-08-26 17:00:38 +02:00
|
|
|
echo -n "Waiting for processes to exit"
|
|
|
|
for loop in 0 1 2 3 4 5 ; do
|
|
|
|
sleep 1
|
|
|
|
echo -n "."
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
|
|
|
|
# Now go to the single user level
|
|
|
|
echo "Going to single user mode..."
|
2018-06-13 07:43:00 +02:00
|
|
|
/sbin/telinit -t 1 1
|
2009-08-26 17:00:38 +02:00
|
|
|
|