4 |
- |
1 |
#! /bin/bash
|
|
|
2 |
#
|
|
|
3 |
# rc This file is responsible for starting/stopping
|
|
|
4 |
# services when the runlevel changes.
|
|
|
5 |
#
|
|
|
6 |
# Original Author:
|
|
|
7 |
# Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
|
|
|
8 |
#
|
|
|
9 |
|
|
|
10 |
set -m
|
|
|
11 |
|
|
|
12 |
# check a file to be a correct runlevel script
|
|
|
13 |
check_runlevel ()
|
|
|
14 |
{
|
|
|
15 |
# Check if the file exists at all.
|
|
|
16 |
[ -x "$1" ] || return 1
|
|
|
17 |
is_ignored_file "$1" && return 1
|
|
|
18 |
return 0
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
# Now find out what the current and what the previous runlevel are.
|
|
|
22 |
argv1="$1"
|
|
|
23 |
set $(/sbin/runlevel)
|
|
|
24 |
runlevel=$2
|
|
|
25 |
previous=$1
|
|
|
26 |
export runlevel previous
|
|
|
27 |
|
|
|
28 |
. /etc/init.d/functions
|
|
|
29 |
|
|
|
30 |
export CONSOLETYPE
|
|
|
31 |
do_confirm="no"
|
|
|
32 |
if [ -f /var/run/confirm ]; then
|
|
|
33 |
do_confirm="yes"
|
|
|
34 |
fi
|
|
|
35 |
UPSTART=
|
|
|
36 |
[ -x /sbin/initctl ] && UPSTART=yes
|
|
|
37 |
# See if we want to be in user confirmation mode
|
|
|
38 |
if [ "$previous" = "N" ]; then
|
|
|
39 |
if [ "$do_confirm" = "yes" ]; then
|
|
|
40 |
echo $"Entering interactive startup"
|
|
|
41 |
else
|
|
|
42 |
echo $"Entering non-interactive startup"
|
|
|
43 |
fi
|
|
|
44 |
fi
|
|
|
45 |
|
|
|
46 |
# Get first argument. Set new runlevel to this argument.
|
|
|
47 |
[ -n "$argv1" ] && runlevel="$argv1"
|
|
|
48 |
|
|
|
49 |
# Is there an rc directory for this new runlevel?
|
|
|
50 |
[ -d /etc/rc$runlevel.d ] || exit 0
|
|
|
51 |
|
|
|
52 |
# Set language, vc settings once to avoid doing it for every init script
|
|
|
53 |
# through functions
|
|
|
54 |
if [ -f /etc/sysconfig/i18n -a -z "${NOLOCALE:-}" ] ; then
|
|
|
55 |
. /etc/profile.d/lang.sh 2>/dev/null
|
|
|
56 |
export LANGSH_SOURCED=1
|
|
|
57 |
fi
|
|
|
58 |
|
|
|
59 |
# First, run the KILL scripts.
|
|
|
60 |
for i in /etc/rc$runlevel.d/K* ; do
|
|
|
61 |
|
|
|
62 |
# Check if the subsystem is already up.
|
|
|
63 |
subsys=${i#/etc/rc$runlevel.d/K??}
|
|
|
64 |
[ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] || continue
|
|
|
65 |
check_runlevel "$i" || continue
|
|
|
66 |
|
|
|
67 |
# Bring the subsystem down.
|
|
|
68 |
[ -n "$UPSTART" ] && initctl emit --quiet stopping JOB=$subsys
|
|
|
69 |
$i stop
|
|
|
70 |
[ -n "$UPSTART" ] && initctl emit --quiet stopped JOB=$subsys
|
|
|
71 |
done
|
|
|
72 |
|
|
|
73 |
# Now run the START scripts.
|
|
|
74 |
for i in /etc/rc$runlevel.d/S* ; do
|
|
|
75 |
|
|
|
76 |
# Check if the subsystem is already up.
|
|
|
77 |
subsys=${i#/etc/rc$runlevel.d/S??}
|
|
|
78 |
[ -f /var/lock/subsys/$subsys ] && continue
|
|
|
79 |
[ -f /var/lock/subsys/$subsys.init ] && continue
|
|
|
80 |
check_runlevel "$i" || continue
|
|
|
81 |
|
|
|
82 |
# If we're in confirmation mode, get user confirmation
|
|
|
83 |
if [ "$do_confirm" = "yes" ]; then
|
|
|
84 |
confirm $subsys
|
|
|
85 |
rc=$?
|
|
|
86 |
if [ "$rc" = "1" ]; then
|
|
|
87 |
continue
|
|
|
88 |
elif [ "$rc" = "2" ]; then
|
|
|
89 |
do_confirm="no"
|
|
|
90 |
fi
|
|
|
91 |
fi
|
|
|
92 |
|
|
|
93 |
update_boot_stage "$subsys"
|
|
|
94 |
# Bring the subsystem up.
|
|
|
95 |
[ -n "$UPSTART" ] && initctl emit --quiet starting JOB=$subsys
|
|
|
96 |
if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then
|
|
|
97 |
export LC_ALL=C
|
|
|
98 |
exec $i start
|
|
|
99 |
fi
|
|
|
100 |
$i start
|
|
|
101 |
[ -n "$UPSTART" ] && initctl emit --quiet started JOB=$subsys
|
|
|
102 |
done
|
|
|
103 |
[ "$do_confirm" = "yes" ] && rm -f /var/run/confirm
|
|
|
104 |
exit 0
|