aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt J. Bosch <kjb-temp-2009@alpenjodel.de>2011-07-02 15:28:10 (GMT)
committerKurt J. Bosch <kjb-temp-2009@alpenjodel.de>2011-07-10 16:08:32 (GMT)
commit02de29190c10dab4d1b43062d71eff11b9c980b5 (patch)
tree2b7dea3254fd0ba3fbf841d449e5af853116dd87
parentd36c8a882bfdb863693d749db980af18d49e4e86 (diff)
downloadinitscripts-02de29190c10dab4d1b43062d71eff11b9c980b5.tar.xz
Refactor kill_everything, fsck_all and mount_all code
Genaral scheme for hook positions is now: run_hook pre_foo if [[$WE_WANT_TO_DO_FOO]]]; then stat_busy "Doing foo" if [[$PRECONDITIONS_FOR_FOO_NOT_SATISFIED]]; then stat_fail else ... stat_done fi fi run hook post_foo rc.sysinit ----------- run_hook pre_foo [[$WE_WANT_TO_DO_FOO]] && status "Doing foo" foo run hook post_foo functions ------------ foo() { [[$PRECONDITIONS_FOR_FOO_NOT_SATISFIED]] && return 1 ... } Rationale Following this scheme as close as possible (without duplicating code and status messages) makes stuff more readable and uniform. Splitting kill_everything() into two new functions stop_all_daemons() and kill_all() also allows customization of either daemons stopping or process killing in an easy way. Suggested-by: Tom Gundersen <teg@jklm.no>
-rw-r--r--functions36
-rwxr-xr-xrc.shutdown8
-rwxr-xr-xrc.single9
-rwxr-xr-xrc.sysinit24
4 files changed, 47 insertions, 30 deletions
diff --git a/functions b/functions
index 7acb855..fd18694 100644
--- a/functions
+++ b/functions
@@ -265,10 +265,10 @@ add_omit_pids() {
omit_pids+=( $@ )
}
-
-kill_everything() {
- # $1 = where we are being called from.
- # This is used to determine which hooks to run.
+# Stop all daemons
+# This function should *never* ever perform any other actions beside calling stop_daemon()!
+# It might be used by a splash system etc. to get a list of daemons to be stopped.
+stop_all_daemons() {
# Find daemons NOT in the DAEMONS array. Shut these down first
local daemon
for daemon in /run/daemons/*; do
@@ -283,10 +283,11 @@ kill_everything() {
[[ ${DAEMONS[i]} = '!'* ]] && continue
ck_daemon ${DAEMONS[i]#@} || stop_daemon ${DAEMONS[i]#@}
done
+}
+kill_all() {
# Terminate all processes
stat_busy "Sending SIGTERM To Processes"
- run_hook "$1_prekillall"
killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null
sleep 5
stat_done
@@ -295,8 +296,6 @@ kill_everything() {
killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null
sleep 1
stat_done
-
- run_hook "$1_postkillall"
}
# Start/trigger UDev, load MODULES and settle UDev
@@ -360,23 +359,14 @@ read_crypttab() {
return $failed
}
+# Filesystem functions
+# These can be overridden/reused for customizations like shutdown/loop-fsck.
NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs"
# Check local filesystems
fsck_all() {
- [[ -x $(type -P fsck) ]] || return 0
- stat_busy "Checking Filesystems"
- FSCK_OUT=/dev/stdout
- FSCK_ERR=/dev/stdout
- FSCK_FD=
- FORCEFSCK=
- [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f"
- run_hook sysinit_prefsck
- fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR
- local -r fsckret=$?
- (( fsckret <= 1 )) && stat_done || stat_fail
- run_hook sysinit_postfsck
- return $fsckret
+ fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR
+ return $?
}
# Single-user login and/or automatic reboot after fsck (if needed)
@@ -415,11 +405,7 @@ fsck_reboot() {
}
mount_all() {
- stat_busy "Mounting Local Filesystems"
- run_hook sysinit_premount
- mount -a -t "$NETFS" -O no_netdev
- run_hook sysinit_postmount
- stat_done
+ mount -a -t "$NETFS" -O no_netdev
}
bootlogd_stop() {
diff --git a/rc.shutdown b/rc.shutdown
index fe42797..ed87eec 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -17,7 +17,13 @@ echo " "
[[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown
-kill_everything shutdown
+stop_all_daemons
+
+run_hook shutdown_prekillall
+
+kill_all
+
+run_hook shutdown_postkillall
stat_busy "Saving Random Seed"
RANDOM_SEED=/var/lib/misc/random-seed
diff --git a/rc.single b/rc.single
index d1efd41..21fe3be 100755
--- a/rc.single
+++ b/rc.single
@@ -11,7 +11,14 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
run_hook single_start
if [[ $PREVLEVEL != N ]]; then
- kill_everything single
+
+ stop_all_daemons
+
+ run_hook single_prekillall
+
+ kill_all
+
+ run_hook single_postkillall
# start up our mini logger until syslog takes over
minilogd
diff --git a/rc.sysinit b/rc.sysinit
index cb0144c..c3610dc 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -174,9 +174,24 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then
fi
# Check filesystems
-fsck_all
+FSCK_OUT=/dev/stdout
+FSCK_ERR=/dev/stdout
+FSCK_FD=
+FORCEFSCK=
+[[ -f /forcefsck ]] || is_in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f"
+run_hook sysinit_prefsck
+if [[ -x $(type -P fsck) ]]; then
+ stat_busy "Checking Filesystems"
+ fsck_all
+ declare -r fsckret=$?
+ (( fsckret <= 1 )) && stat_done || stat_fail
+else
+ declare -r fsckret=0
+fi
+run_hook sysinit_postfsck
+
# Single-user login and/or automatic reboot if needed
-fsck_reboot $?
+fsck_reboot $fsckret
status "Remounting Root Read/Write" \
mount -n -o remount,rw /
@@ -193,7 +208,10 @@ if [[ ! -L /etc/mtab ]]; then
fi
# now mount all the local filesystems
-mount_all
+run_hook sysinit_premount
+status "Mounting Local Filesystems" \
+ mount_all
+run_hook sysinit_postmount
# enable monitoring of lvm2 groups, now that the filesystems are mounted rw
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] &&