Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
69a1c39cbc | |||
c799ab796b | |||
24d64da2ed | |||
b640a64e21 | |||
fced4775b1 | |||
58054382e2 | |||
04ff160a7d |
3
rc.conf
3
rc.conf
@@ -40,3 +40,6 @@ cfg_mounts=(
|
|||||||
# Some temporary directories and files
|
# Some temporary directories and files
|
||||||
cfg_tmpdirs+=( '/run/lock' '/run/lock/lvm' '/run/lvm' '/run/user' )
|
cfg_tmpdirs+=( '/run/lock' '/run/lock/lvm' '/run/lvm' '/run/user' )
|
||||||
cfg_tmpfiles+=( '/run/utmp' )
|
cfg_tmpfiles+=( '/run/utmp' )
|
||||||
|
|
||||||
|
# How long do we wait for all processes to die nicely?
|
||||||
|
cfg_killall5_timeout=30
|
||||||
|
8
rc.in
8
rc.in
@@ -101,10 +101,10 @@ rc.services_stop() {
|
|||||||
|
|
||||||
rc.stop_everything() {
|
rc.stop_everything() {
|
||||||
echo "Politely asking all processes to shut down..."
|
echo "Politely asking all processes to shut down..."
|
||||||
killall5 -15; sleep 3
|
killall5 -s 15 -w "$cfg_killall5_timeout"
|
||||||
|
|
||||||
echo "Killing the remaning ones..."
|
echo "Killing the remaning ones..."
|
||||||
killall5 -9
|
killall5 -s 9
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.unmount_everything() {
|
rc.unmount_everything() {
|
||||||
@@ -129,10 +129,10 @@ rc.boot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc.halt() {
|
rc.halt() {
|
||||||
if type -P halt; then
|
if type -P halt &>/dev/null; then
|
||||||
function rc.halt_poweroff { halt -p; }
|
function rc.halt_poweroff { halt -p; }
|
||||||
function rc.halt_reboot { halt -r; }
|
function rc.halt_reboot { halt -r; }
|
||||||
elif [[ -f /proc/sysrq-trigger ]]; then
|
elif (( $(</proc/sys/kernel/sysrq) )); then
|
||||||
function rc.halt_poweroff { echo 'o' > /proc/sysrq-trigger; }
|
function rc.halt_poweroff { echo 'o' > /proc/sysrq-trigger; }
|
||||||
function rc.halt_reboot { echo 'b' > /proc/sysrq-trigger; }
|
function rc.halt_reboot { echo 'b' > /proc/sysrq-trigger; }
|
||||||
else
|
else
|
||||||
|
@@ -37,14 +37,60 @@ get_procs_to_kill() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pids_exist() {
|
||||||
|
for i in "$@"; do
|
||||||
|
if kill -0 "$i" 2>/dev/null; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_wait() {
|
||||||
|
declare counter
|
||||||
|
|
||||||
|
while pids_exist "$@"; do
|
||||||
|
if (( counter == timeout )); then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
(( counter++ ))
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
timeout=30
|
||||||
|
signal=15
|
||||||
|
|
||||||
|
while (( $# )); do
|
||||||
|
case $1 in
|
||||||
|
-w)
|
||||||
|
flag_wait=1
|
||||||
|
timeout=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
|
-s)
|
||||||
|
signal=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
my_tree=( $(get_my_tree) self thread-self )
|
my_tree=( $(get_my_tree) self thread-self )
|
||||||
all_procs=( $(get_all_procs) )
|
all_procs=( $(get_all_procs) )
|
||||||
procs_to_kill=( $(get_procs_to_kill) )
|
procs_to_kill=( $(get_procs_to_kill) )
|
||||||
|
|
||||||
signal="${1:-"-15"}"
|
kill -n "$signal" "${procs_to_kill[@]}" 2>/dev/null
|
||||||
|
|
||||||
kill "$signal" "${procs_to_kill[@]}" 2>/dev/null
|
if (( flag_wait )); then
|
||||||
|
pid_wait "${procs_to_kill[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user