aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d/rc
blob: c938e531f121e5001e570a45284f4ddfd5f64fb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /bin/bash
#
# rc            This file is responsible for starting/stopping
#               services when the runlevel changes.
#
# Original Author:       
#               Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#

# Now find out what the current and what the previous runlevel are.
argv1="$1"
set `/sbin/runlevel`
runlevel=$2
previous=$1
export runlevel previous

. /etc/init.d/functions

# See if we want to be in user confirmation mode
if [ "$previous" = "N" ]; then
	if grep -i confirm /proc/cmdline >/dev/null \
			|| [ -f /var/run/confirm ] ; then
		rm -f /var/run/confirm
		CONFIRM=yes
		echo $"Entering interactive startup"
	else
		CONFIRM=
		echo $"Entering non-interactive startup"
	fi
fi
export CONFIRM

# Get first argument. Set new runlevel to this argument.
[ -n "$argv1" ] && runlevel="$argv1"

# Is there an rc directory for this new runlevel?
[ -d /etc/rc$runlevel.d ] || exit 0

# First, run the KILL scripts.
for i in /etc/rc$runlevel.d/K*; do
	# Check if the script is there.
	[ -f $i ] || continue

	# Don't run [KS]??foo.{rpmsave,rpmorig} scripts
	[ "${i%.rpmsave}" != "$i" ] && continue
	[ "${i%.rpmorig}" != "$i" ] && continue
	[ "${i%.rpmnew}" != "$i" ] && continue

	# Check if the subsystem is already up.
	subsys=${i#/etc/rc$runlevel.d/K??}
	[ -f /var/lock/subsys/$subsys ] || \
		[ -f /var/lock/subsys/${subsys}.init ] || continue

	# Bring the subsystem down.
	if egrep -q "(killproc |action )" $i ; then
		$i stop
	else
		action $"Stopping $subsys: " $i stop
	fi
done

# Now run the START scripts.
for i in /etc/rc$runlevel.d/S*; do
	# Check if the script is there.
	[ -f $i ] || continue

	# Don't run [KS]??foo.{rpmsave,rpmorig} scripts
	[ "${i%.rpmsave}" != "$i" ] && continue
	[ "${i%.rpmorig}" != "$i" ] && continue
	[ "${i%.rpmnew}" != "$i" ] && continue

	# Check if the subsystem is already up.
	subsys=${i#/etc/rc$runlevel.d/S??}
	[ -f /var/lock/subsys/$subsys ] || \
		[ -f /var/lock/subsys/${subsys}.init ] && continue
		    
	# If we're in confirmation mode, get user confirmation
	if [ -n "$CONFIRM" ]; then
		confirm $subsys
		case $? in
			0) :;;
			2) CONFIRM=;;
			*) continue;;
		esac 
	fi

	# Bring the subsystem up.
	if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then
		unset LANG
		unset LC_ALL
		exec $i start
	fi
	if egrep -q "(daemon |action )" $i \
			|| [ "$subsys" = "single" -o "$subsys" = "local" ]; then
		$i start
	else
		action $"Starting $subsys: " $i start
	fi
done