aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d/rc
blob: 3d4b96f6d71433b74e638b2ba0a1b71452c61243 (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
#!/bin/bash
#
# rc            This file is responsible for starting/stopping
#               services when the runlevel changes. It is also
#               responsible for the very first setup of basic
#               things, such as setting the hostname.
#
# Original Author:       
#               Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#

# Source function library.
. /etc/rc.d/init.d/functions

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

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

# Is there an rc directory for this new runlevel?
if [ -d /etc/rc.d/rc$runlevel.d ]; then
	# First, run the KILL scripts.
	for i in /etc/rc.d/rc$runlevel.d/K*; do
		# Check if the script is there.
		[ ! -f $i ] && continue

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

		# Bring the subsystem down.
		$i stop
	done

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

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

		# Bring the subsystem up.
		$i start
	done
fi