1 | #!/bin/sh
|
---|
2 | ########################################################################
|
---|
3 | # Begin rc
|
---|
4 | #
|
---|
5 | # Description : Main Run Level Control Script
|
---|
6 | #
|
---|
7 | # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
|
---|
8 | # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
|
---|
9 | #
|
---|
10 | # Version : LFS 7.0
|
---|
11 | #
|
---|
12 | ########################################################################
|
---|
13 |
|
---|
14 | . /lib/boot/functions
|
---|
15 |
|
---|
16 | print_error_msg()
|
---|
17 | {
|
---|
18 | echo_failure
|
---|
19 | # $i is set when called
|
---|
20 | boot_mesg -n "FAILURE:\n\nYou should not be reading this error message.\n\n" ${FAILURE}
|
---|
21 | boot_mesg -n " It means that an unforeseen error took"
|
---|
22 | boot_mesg -n " place in ${i}, which exited with a return value of"
|
---|
23 | boot_mesg " ${error_value}.\n"
|
---|
24 | boot_mesg_flush
|
---|
25 | boot_mesg -n "If you're able to track this"
|
---|
26 | boot_mesg -n " error down to a bug in one of the files provided by"
|
---|
27 | boot_mesg -n " the LFS book, please be so kind to inform us at"
|
---|
28 | boot_mesg " lfs-dev@linuxfromscratch.org.\n"
|
---|
29 | boot_mesg_flush
|
---|
30 | boot_mesg -n "Press Enter to continue..." ${INFO}
|
---|
31 | boot_mesg "" ${NORMAL}
|
---|
32 | wait_for_user
|
---|
33 | }
|
---|
34 |
|
---|
35 | check_script_status()
|
---|
36 | {
|
---|
37 | # $i is set when called
|
---|
38 | if [ ! -f ${i} ]; then
|
---|
39 | boot_mesg "${i} is not a valid symlink." ${WARNING}
|
---|
40 | echo_warning
|
---|
41 | continue
|
---|
42 | fi
|
---|
43 |
|
---|
44 | if [ ! -x ${i} ]; then
|
---|
45 | boot_mesg "${i} is not executable, skipping." ${WARNING}
|
---|
46 | echo_warning
|
---|
47 | continue
|
---|
48 | fi
|
---|
49 | }
|
---|
50 |
|
---|
51 | # This sets a few default terminal options.
|
---|
52 | stty sane
|
---|
53 |
|
---|
54 | # These 3 signals will not cause our script to exit
|
---|
55 | trap "" INT QUIT TSTP
|
---|
56 |
|
---|
57 | [ "${1}" != "" ] && runlevel=${1}
|
---|
58 |
|
---|
59 | if [ "${runlevel}" = "" ]; then
|
---|
60 | echo "Usage: ${0} <runlevel>" >&2
|
---|
61 | exit 1
|
---|
62 | fi
|
---|
63 |
|
---|
64 | previous=${PREVLEVEL}
|
---|
65 | [ "${previous}" = "" ] && previous=N
|
---|
66 |
|
---|
67 | if [ ! -d /etc/rc.d/rc${runlevel}.d ]; then
|
---|
68 | boot_mesg "/etc/rc.d/rc${runlevel}.d does not exist."
|
---|
69 | exit 1
|
---|
70 | fi
|
---|
71 |
|
---|
72 | # Attempt to stop all services started by the previous runlevel,
|
---|
73 | # and killed in this runlevel
|
---|
74 | if [ "${previous}" != "N" ]; then
|
---|
75 | for i in $(ls -v /etc/rc.d/rc${runlevel}.d/K* 2> /dev/null)
|
---|
76 | do
|
---|
77 | check_script_status
|
---|
78 |
|
---|
79 | suffix=${i#/etc/rc.d/rc$runlevel.d/K[0-9][0-9]}
|
---|
80 | prev_start=/etc/rc.d/rc$previous.d/S[0-9][0-9]$suffix
|
---|
81 | sysinit_start=/etc/rc.d/rcsysinit.d/S[0-9][0-9]$suffix
|
---|
82 |
|
---|
83 | if [ "${runlevel}" != "0" ] && [ "${runlevel}" != "6" ]; then
|
---|
84 | if [ ! -f ${prev_start} ] && [ ! -f ${sysinit_start} ]; then
|
---|
85 | boot_mesg -n "WARNING:\n\n${i} can't be" ${WARNING}
|
---|
86 | boot_mesg -n " executed because it was not"
|
---|
87 | boot_mesg -n " not started in the previous"
|
---|
88 | boot_mesg -n " runlevel (${previous})."
|
---|
89 | boot_mesg "" ${NORMAL}
|
---|
90 | boot_mesg_flush
|
---|
91 | continue
|
---|
92 | fi
|
---|
93 | fi
|
---|
94 | ${i} stop
|
---|
95 | error_value=${?}
|
---|
96 |
|
---|
97 | if [ "${error_value}" != "0" ]; then
|
---|
98 | print_error_msg
|
---|
99 | fi
|
---|
100 | done
|
---|
101 | fi
|
---|
102 |
|
---|
103 | if [ "${previous}" = "N" ]; then
|
---|
104 | IN_BOOT=1
|
---|
105 | export IN_BOOT
|
---|
106 | fi
|
---|
107 |
|
---|
108 | #Start all functions in this runlevel
|
---|
109 | for i in $( ls -v /etc/rc.d/rc${runlevel}.d/S* 2> /dev/null)
|
---|
110 | do
|
---|
111 | if [ "${previous}" != "N" ]; then
|
---|
112 | suffix=${i#/etc/rc.d/rc$runlevel.d/S[0-9][0-9]}
|
---|
113 | stop=/etc/rc.d/rc$runlevel.d/K[0-9][0-9]$suffix
|
---|
114 | prev_start=/etc/rc.d/rc$previous.d/S[0-9][0-9]$suffix
|
---|
115 |
|
---|
116 | [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue
|
---|
117 | fi
|
---|
118 |
|
---|
119 | check_script_status
|
---|
120 |
|
---|
121 | case ${runlevel} in
|
---|
122 | 0|6)
|
---|
123 | ${i} stop
|
---|
124 | ;;
|
---|
125 | *)
|
---|
126 | ${i} start
|
---|
127 | ;;
|
---|
128 | esac
|
---|
129 | error_value=${?}
|
---|
130 |
|
---|
131 | if [ "${error_value}" != "0" ]; then
|
---|
132 | print_error_msg
|
---|
133 | fi
|
---|
134 | done
|
---|
135 |
|
---|
136 | # End rc
|
---|