aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--functions31
-rwxr-xr-xrc.shutdown36
-rwxr-xr-xrc.single33
3 files changed, 34 insertions, 66 deletions
diff --git a/functions b/functions
index 3fc6fa9..84fed85 100644
--- a/functions
+++ b/functions
@@ -202,6 +202,37 @@ ck_status() {
fi
}
+kill_everything() {
+ # $1 = where we are being called from.
+ # This is used to determine which hooks to run.
+ # Find daemons NOT in the DAEMONS array. Shut these down first
+ for daemon in /var/run/daemons/*; do
+ [[ -f $daemon ]] || continue
+ daemon=${daemon##*/}
+ in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon"
+ done
+
+ # Shutdown daemons in reverse order
+ for ((i=${#DAEMONS[@]}-1; i>=0; i--)); do
+ [[ ${DAEMONS[$i]:0:1} = '!' ]] && continue
+ ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@}
+ done
+
+ # Terminate all processes
+ stat_busy "Sending SIGTERM To Processes"
+ run_hook "$1_prekillall"
+ /sbin/killall5 -15 &> /dev/null
+ /bin/sleep 5
+ stat_done
+
+ stat_busy "Sending SIGKILL To Processes"
+ /sbin/killall5 -9 &> /dev/null
+ /bin/sleep 1
+ stat_done
+
+ run_hook "$1_postkillall"
+}
+
###############################
# Custom hooks in initscripts #
###############################
diff --git a/rc.shutdown b/rc.shutdown
index 4eb29cc..d540364 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -19,41 +19,9 @@ echo " "
if [ -x /bin/domainname ]; then
/bin/domainname ""
fi
+[[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown
-if [ -x /etc/rc.local.shutdown ]; then
- /etc/rc.local.shutdown
-fi
-
-# Find daemons NOT in the DAEMONS array. Shut these down first
-if [ -d /var/run/daemons ]; then
- for daemon in $(/bin/ls -1t /var/run/daemons); do
- if ! in_array $daemon ${DAEMONS[@]}; then
- stop_daemon $daemon
- fi
- done
-fi
-# Shutdown daemons in reverse order
-let i=${#DAEMONS[@]}-1
-while [ $i -ge 0 ]; do
- if [ "${DAEMONS[$i]:0:1}" != '!' ]; then
- ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@}
- fi
- let i=i-1
-done
-
-# Terminate all processes
-stat_busy "Sending SIGTERM To Processes"
-run_hook shutdown_prekillall
-/sbin/killall5 -15 &> /dev/null
-/bin/sleep 5
-stat_done
-
-stat_busy "Sending SIGKILL To Processes"
-/sbin/killall5 -9 &> /dev/null
-/bin/sleep 1
-stat_done
-
-run_hook shutdown_postkillall
+kill_everything shutdown
stat_busy "Saving Random Seed"
RANDOM_SEED=/var/lib/misc/random-seed
diff --git a/rc.single b/rc.single
index aa58b4c..2e757d9 100755
--- a/rc.single
+++ b/rc.single
@@ -9,38 +9,7 @@
run_hook single_start
if [[ $PREVLEVEL != N ]]; then
-
- # Find daemons NOT in the DAEMONS array. Shut these down first
- if [[ -d /var/run/daemons ]]; then
- for daemon in $(/bin/ls -1t /var/run/daemons); do
- if ! in_array $daemon ${DAEMONS[@]}; then
- stop_daemon $daemon
- fi
- done
- fi
- # Shutdown daemons in reverse order
- let i=${#DAEMONS[@]}-1
- while ((i >= 0)); do
- if [[ ${DAEMONS[$i]:0:1} != '!' ]]; then
- ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@}
- fi
- let i=i-1
- done
-
- # Terminate all processes
- stat_busy "Sending SIGTERM To Processes"
- run_hook single_prekillall
- /sbin/killall5 -15 &> /dev/null
- /bin/sleep 5
- stat_done
-
- stat_busy "Sending SIGKILL To Processes"
- /sbin/killall5 -9 &> /dev/null
- /bin/sleep 1
- stat_done
-
- run_hook single_postkillall
-
+ kill_everything single
stat_busy "Starting UDev Daemon"
/sbin/udevd --daemon
stat_done