]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc
- removed "scripts" method of executing external programs after uping
[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.19 2000/03/27 16:07:50 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 # NLS
16 if [ -f /etc/sysconfig/i18n ]; then
17         . /etc/sysconfig/i18n
18         [ -n "$LANG" ] && export LANG || unset LANG
19         [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE
20         [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE
21         [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES
22         [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC
23         [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY
24         [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME
25         [ -n "$LC_ALL" ] && export LC_ALL || unset LC_ALL
26         [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE
27         [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS
28 fi
29
30 # Source function library.
31 . /etc/rc.d/init.d/functions
32
33 # Read system config data.
34 if [ -f /etc/sysconfig/system ]; then
35         . /etc/sysconfig/system
36 else
37         RUN_SULOGIN_ON_ERR=yes
38         RUN_ISAPNP=yes
39         PANIC_REBOOT_TIME=0
40         DELAY_LOGIN=yes
41         CLEAN_TMP=no
42         CONSOLE_LOGLEVEL=1
43         LOAD_SOUND=yes
44         SET_SLINKS=yes
45         RUN_LDCONFIG=yes
46 fi
47
48 # Now find out what the current and what the previous runlevel are.
49 argv1="$1"
50 set `/sbin/runlevel`
51 runlevel=$2
52 previous=$1
53 export runlevel previous
54
55 # if runlevel is 0 (halt) or 6 (reboot) change to first
56 # virtual console, and send messages to /dev/console 
57 # (it can be serial console too) 
58 if [ "$runlevel" = "0" ] || [ "$runlevel" = "6" ]; then
59         [ -x /usr/bin/chvt ] && /usr/bin/chvt 1 && echo > /dev/console
60         exec 0<> /dev/console 1>&0 2>&0
61 else
62 # if previous runlevel = current runlevel do nothing
63         [ "$runlevel" = "$previous" ] && exit 0
64 fi
65
66 # See if we want to be in user confirmation mode
67 if [ "$previous" = "N" ]; then
68         if grep -qi confirm /proc/cmdline >/dev/null \
69                 || [ -f /var/run/confirm ]; then
70                 rm -f /var/run/confirm
71                 CONFIRM="yes"
72                 nls "Entering interactive startup"
73         else
74                 CONFIRM=
75                 nls "Entering non-interactive startup"
76         fi
77 fi
78                                           
79 # set onlcr to avoid staircase effect and do not lock scrolling
80 stty onlcr -ixon 0>&1
81
82 # Get first argument. Set new runlevel to this argument.
83 [ "$1" != "" ] && runlevel="$argv1"
84
85 # Tell linuxconf what runlevel we are in
86 [ -d /var/run -a -w /var/run ] && echo "/etc/rc.d/rc$runlevel.d" > /var/run/runlevel.dir
87
88
89 # Say something ;)
90 af2="`termput setaf 2`"
91 af7="`termput setaf 7`"
92 text="`nls "%sResource Manager: %sEntering runlevel number" $af2 $af7`"
93 text_size="`nls "%sResource Manager: %sEntering runlevel number" 0 0`"
94 unset af2 af7
95 echo -n "$text"
96 awk "BEGIN { for (j=length(\"$text_size\")-9; j<$INIT_COL; j++) printf \".\" }"
97 echo "`termput setaf 6`[`termput setaf 2` $runlevel `termput setaf 6`]`termput setaf 7`"
98
99 # Is there an rc directory for this new runlevel?
100 if [ -d /etc/rc.d/rc$runlevel.d ]; then
101         # First, run the KILL scripts.
102         for i in /etc/rc.d/rc$runlevel.d/K*; do
103                 # Check if the script is there.
104                 [ ! -f $i ] && continue
105
106                 # Don't run [KS]??foo.{rpmsave,rpmorig,rpmnew} scripts
107                 [ "${1%.rpmsave}" != "${1}" ] && continue
108                 [ "${1%.rpmorig}" != "${1}" ] && continue
109                 [ "${1%.rpmnew}" != "${1}" ] && continue
110
111                 # Check if the subsystem is already up.
112                 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
113                 [ ! -f /var/lock/subsys/$subsys ] && \
114                     [ ! -f /var/lock/subsys/${subsys}.init ] && continue
115
116                 # Bring the subsystem down.
117                 $i stop
118         done
119
120         # Now run the START scripts.
121         for i in /etc/rc.d/rc$runlevel.d/S*; do
122                 # Check if the script is there.
123                 [ ! -f $i ] && continue
124
125                 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
126                 [ "${1%.rpmsave}" != "${1}" ] && continue
127                 [ "${1%.rpmorig}" != "${1}" ] && continue
128                 [ "${1%.rpmnew}" != "${1}" ] && continue
129
130                 # Check if the subsystem is already up.
131                 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
132                 [ -f /var/lock/subsys/$subsys ] || \
133                     [ -f /var/lock/subsys/${subsys}.init ] && continue
134
135                 # If we're in confirmation mode, get user confirmation
136                 [ -n "$CONFIRM" ]  &&
137                 {
138                         confirm $subsys
139                         case $? in
140                           0)
141                                 :
142                           ;;
143                           2)
144                                 CONFIRM=
145                           ;;
146                           *)
147                                 continue
148                           ;;
149                         esac
150                 }
151
152                 # Bring the subsystem up.
153                 $i start
154         done
155 fi
156
157 # if runlevel is 0 (halt) or 6 (reboot) run rc.shutdown
158 if [ "$runlevel" = "0" ] || [ "$runlevel" = "6" ]; then
159         /etc/rc.d/rc.shutdown
160         if [ "$runlevel" = "0" ] ; then
161                 show "The system is halted"; ok
162                 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
163                 eval halt -d
164         else
165                 show "Please stand by while rebooting the system"; ok
166                 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
167                 eval reboot -d
168         fi
169 else
170         if [ "$RUN_LDCONFIG" = "yes" -o ! -f /etc/ld.so.cache ] ; then
171                 if [ -x /sbin/ldconfig ]; then
172                         run_cmd "Setting up /etc/ld.so.cache" /sbin/ldconfig -X
173                 fi
174         fi
175 fi
176
177 # Say something ;)
178 af2="`termput setaf 2`"
179 af7="`termput setaf 7`"
180 text="`nls "%sResource Manager: %sRunlevel has been reached" $af2 $af7`"
181 text_size="`nls "%sResource Manager: %sRunlevel has been reached" 0 0`"
182 unset af2 af7
183 echo -n "$text"
184 awk "BEGIN { for (j=length(\"$text_size\")-9; j<$INIT_COL; j++) printf \".\" }"
185 echo "`termput setaf 6`[`termput setaf 2` $runlevel `termput setaf 6`]`termput setaf 7`"
186
This page took 0.046617 seconds and 4 git commands to generate.