Am 2010-06-30 23:47, schrieb Victor Lowther:
Move that shared code into functions.
---
  functions   |   29 +++++++++++++++++++++++++++++
  rc.shutdown |   32 +-------------------------------
  rc.single   |   27 +--------------------------
  3 files changed, 31 insertions(+), 57 deletions(-)

diff --git a/functions b/functions
index d8e8e54..bf6ed45 100644
--- a/functions
+++ b/functions
@@ -203,6 +203,35 @@ ck_status() {
    fi
  }

+kill_everything() {
+    # 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" "${daemo...@]}" || stop_daemon "$daemon"
+    done
+       
+    # Shutdown daemons in reverse order
+    for ((i=${#daemo...@]}-1; i>=0; i--)); do
+       [[ ${DAEMONS[$i]:0:1} = '!' ]]&&  continue
+       ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
+    done
+
+       # Terminate all processes
+    stat_busy "Sending SIGTERM To Processes"
+    run_hook single_prekillall

This line should be  run_hook "${0##*/rc.}"_prekillall  IMHO


+    /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

Similar as above.

+}
+
  ###############################
  # Custom hooks in initscripts #
  ###############################
diff --git a/rc.shutdown b/rc.shutdown
index 002a45d..ef9b16d 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -19,37 +19,7 @@ echo " "
  [[ -x /bin/domainname ]]&&  /bin/domainname ""
  [[ -x /etc/rc.local.shutdown ]]&&  /etc/rc.local.shutdown

-
-# 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 ${daemo...@]}; then
-                       stop_daemon $daemon
-               fi
-       done
-fi
-# Shutdown daemons in reverse order
-let i=${#daemo...@]}-1
-while [ $i -ge 0 ]; do
-       if [ "${DAEMONS[$i]:0:1}" != '!' ]; then
-               ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
-       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

  stat_busy "Saving Random Seed"
  RANDOM_SEED=/var/lib/misc/random-seed
diff --git a/rc.single b/rc.single
index aa27be0..a84ece8 100755
--- a/rc.single
+++ b/rc.single
@@ -9,33 +9,8 @@
  run_hook single_start

  if [[ $PREVLEVEL != N ]]; then
-    # 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" "${daemo...@]}" || stop_daemon "$daemon"
-    done
-       
-    # Shutdown daemons in reverse order
-    for ((i=${#daemo...@]}-1; i>=0; i--)); do
-       [[ ${DAEMONS[$i]:0:1} = '!' ]]&&  continue
-       ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
-    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
        stat_busy "Starting UDev Daemon"
        /sbin/udevd --daemon
        stat_done


Reply via email to