From 9390083d675e1fd5059ab35d9977bf84b7d87ba2 Mon Sep 17 00:00:00 2001 From: Victor Lowther Date: Mon, 7 Jun 2010 10:24:43 -0500 Subject: Both rc.single and rc.shutdown use the same code to kill everything. Simplify it, and move that shared code into functions. Parsing the output of ls is Bad, especially when globbing works just as well and does not get confused by odd characters in filenames. bash has arithemetic for loops. Use them instead of while loops for iterating over arrays. --- functions | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'functions') 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 # ############################### -- cgit v1.2.3