]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc
0ed821b132ca16586440eb721edf584ea5a2e5bf
[projects/rc-scripts.git] / rc.d / rc
1 #!/bin/sh
2 #
3 # rc            This file is responsible for starting/stopping
4 #               services when the runlevel changes. It is also
5 #               responsible for the very first setup of basic
6 #               things, such as setting the hostname.
7 #
8 # $Id: rc,v 1.25.2.2 2001/05/13 17:47:45 misiek Exp $
9 #
10 # Original Author:       
11 #               Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
12 # Changes:      Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
13 #
14
15 # avoid being interrupted by child or keyboard
16 trap ":" INT QUIT TSTP
17
18 # Save argument
19 argv1="$1"
20
21 # Get terminal size of standard input of the system console
22 [ -z "$CONSOLE" ] && CONSOLE=/dev/console
23 set -- $(stty size < $CONSOLE)
24   LINES=$1
25 COLUMNS=$2
26 export LINES COLUMNS CONSOLE
27   
28 # NLS
29 if [ -f /etc/sysconfig/i18n ]; then
30         . /etc/sysconfig/i18n
31         [ -n "$LANG" ] && export LANG || unset LANG
32         [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE
33         [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE
34         [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES
35         [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC
36         [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY
37         [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME
38         [ -n "$LC_ALL" ] && export LC_ALL || unset LC_ALL
39         [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE
40         [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS
41 fi
42
43 # Source function library.
44 . /etc/rc.d/init.d/functions
45
46 # Read system config data.
47 if [ -f /etc/sysconfig/system ]; then
48         . /etc/sysconfig/system
49 else
50         RUN_SULOGIN_ON_ERR=yes
51         RUN_ISAPNP=yes
52         PANIC_REBOOT_TIME=0
53         DELAY_LOGIN=yes
54         CLEAN_TMP=no
55         CONSOLE_LOGLEVEL=1
56         LOAD_SOUND=yes
57         SET_SLINKS=yes
58         RUN_LDCONFIG=yes
59 fi
60
61 # Now find out what the current and what the previous runlevel are.
62 set $(/sbin/runlevel)
63 runlevel=$2
64 previous=$1
65 export runlevel previous
66
67 # if previous runlevel = current runlevel do nothing
68 [ "$runlevel" = "$previous" ] && exit 0
69
70 # if runlevel is 0 (halt) or 6 (reboot) change to first
71 # virtual console, and send messages to /dev/console 
72 # (it can be serial console too) 
73 if [ "$COLUMNS" -gt 0 ]; then
74         if [ "$runlevel" = "0" -o "$runlevel" = "6" ]; then
75                 CONSOLE=/dev/tty1
76                 [ -x /usr/bin/chvt ] && /usr/bin/chvt 1 && echo > $CONSOLE
77                 exec 0<> /dev/console 1>&0 2>&0
78         fi
79 else
80         # Serial: columns and lines are not defined
81           LINES=24
82         COLUMNS=80
83 fi
84
85 # See if we want to be in user confirmation mode
86 if [ "$previous" = "N" ]; then
87         if grep -qi confirm /proc/cmdline >/dev/null \
88                 || [ -f /var/run/confirm ]; then
89                 rm -f /var/run/confirm
90                 CONFIRM="yes"
91                 nls "Entering interactive startup"
92         else
93                 CONFIRM=
94                 nls "Entering non-interactive startup"
95         fi
96 fi
97                                           
98 # set onlcr to avoid staircase effect and do not lock scrolling
99 stty onlcr -ixon 0>&1
100
101 # Get first argument. Set new runlevel to this argument.
102 [ -n "$1" ] && runlevel="$argv1"
103
104 # Tell linuxconf what runlevel we are in
105 [ -d /var/run -a -w /var/run ] && echo "/etc/rc.d/rc$runlevel.d" > /var/run/runlevel.dir
106
107
108 # Say something ;)
109 af2=$(termput setaf 2)
110 af6=$(termput setaf 6)
111 af7=$(termput setaf 7)
112 text="$(termput op)$(nls '%sResource Manager: %sEntering runlevel number' "$af2" "$af7")"
113 text_size="$(nls '%sResource Manager: %sEntering runlevel number' "" "")"
114 resp_size="$(nls 'DONE')"
115 echo -n "$text"
116 awk "BEGIN { for (j=length(\"$text_size\"); j<$INIT_COL+${#resp_size}-${#runlevel}; j++) printf \".\" }"
117 echo "${af6}[${af2} $runlevel ${af6}]${af7}"
118
119 # Is there an rc directory for this new runlevel?
120 if [ -d /etc/rc.d/rc$runlevel.d ]; then
121         # First, run the KILL scripts.
122         for i in /etc/rc.d/rc$runlevel.d/K*; do
123                 # Check if the script is there.
124                 [ ! -f $i ] && continue
125
126                 # Don't run [KS]??foo.{rpmsave,rpmorig,rpmnew} scripts
127                 [ "${1%.rpmsave}" != "${1}" ] && continue
128                 [ "${1%.rpmorig}" != "${1}" ] && continue
129                 [ "${1%.rpmnew}" != "${1}" ] && continue
130
131                 # Check if the subsystem is already up.
132                 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
133                 [ ! -f /var/lock/subsys/$subsys ] && \
134                     [ ! -f /var/lock/subsys/${subsys}.init ] && continue
135
136                 # Bring the subsystem down.
137                 $i stop
138         done
139
140         # Now run the START scripts.
141         for i in /etc/rc.d/rc$runlevel.d/S*; do
142                 # Check if the script is there.
143                 [ ! -f $i ] && continue
144
145                 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
146                 [ "${1%.rpmsave}" != "${1}" ] && continue
147                 [ "${1%.rpmorig}" != "${1}" ] && continue
148                 [ "${1%.rpmnew}" != "${1}" ] && continue
149
150                 # Check if the subsystem is already up.
151                 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
152                 [ -f /var/lock/subsys/$subsys ] || \
153                     [ -f /var/lock/subsys/${subsys}.init ] && continue
154
155                 # If we're in confirmation mode, get user confirmation
156                 [ -n "$CONFIRM" ]  &&
157                 {
158                         confirm $subsys
159                         case $? in
160                           0)
161                                 :
162                           ;;
163                           2)
164                                 CONFIRM=
165                           ;;
166                           *)
167                                 continue
168                           ;;
169                         esac
170                 }
171
172                 # Bring the subsystem up.
173                 $i start
174         done
175 fi
176
177 # if runlevel is 0 (halt) or 6 (reboot) run rc.shutdown
178 if [ "$runlevel" = "0" ] || [ "$runlevel" = "6" ]; then
179         /etc/rc.d/rc.shutdown
180         if [ "$runlevel" = "0" ] ; then
181                 show "The system is halted"; ok
182                 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
183                 eval halt -d -p
184         else
185                 show "Please stand by while rebooting the system"; ok
186                 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
187                 eval reboot -d
188         fi
189 else
190         if is_yes "$RUN_LDCONFIG" || [ ! -f /etc/ld.so.cache ] ; then
191                 if [ -x /sbin/ldconfig ]; then
192                         run_cmd "Setting up /etc/ld.so.cache" /sbin/ldconfig -X
193                 fi
194         fi
195 fi
196
197 # Say something ;)
198 text="$(nls '%sResource Manager: %sRunlevel has been reached' "$af2" "$af7")"
199 text_size="$(nls '%sResource Manager: %sRunlevel has been reached' "" "")"
200 echo -n "$text"
201 awk "BEGIN { for (j=length(\"$text_size\"); j<$INIT_COL+${#resp_size}-${#runlevel}; j++) printf \".\" }"
202 echo "${af6}[${af2} $runlevel ${af6}]${af7}"
203 unset af2 af6 af7
204
205 exit 0
206
207 # This must be last line !
208 # vi:syntax=sh:tw=78:ts=8:sw=4
209
This page took 0.037204 seconds and 3 git commands to generate.