]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc
- support exit code defined in LSB spec (http://www.linuxbase.org/)
[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.16 2000/01/04 17:23:39 baggins 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
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 # set onlcr to avoid staircase effect and do not lock scrolling
67 stty onlcr -ixon 0>&1
68
69 # Get first argument. Set new runlevel to this argument.
70 [ "$1" != "" ] && runlevel="$argv1"
71
72 # Tell linuxconf what runlevel we are in
73 [ -d /var/run -a -w /var/run ] && echo "/etc/rc.d/rc$runlevel.d" > /var/run/runlevel.dir
74
75
76 # Say something ;)
77 af2="`termput setaf 2`"
78 af7="`termput setaf 7`"
79 line="............................................................................"
80 text="`nls "%sResource Manager: %sEntering runlevel number%s" $af2 $af7 $line`"
81 unset af2 af7 line
82 awk "BEGIN {printf \"%.78s\", \"$text\";}"
83 echo "`termput setaf 6`[`termput setaf 2` $runlevel `termput setaf 6`]`termput setaf 7`"
84
85 # Is there an rc directory for this new runlevel?
86 if [ -d /etc/rc.d/rc$runlevel.d ]; then
87         # First, run the KILL scripts.
88         for i in /etc/rc.d/rc$runlevel.d/K*; do
89                 # Check if the script is there.
90                 [ ! -f $i ] && continue
91
92                 # Don't run [KS]??foo.{rpmsave,rpmorig,rpmnew} scripts
93                 [ "${1%.rpmsave}" != "${1}" ] && continue
94                 [ "${1%.rpmorig}" != "${1}" ] && continue
95                 [ "${1%.rpmnew}" != "${1}" ] && continue
96
97                 # Check if the subsystem is already up.
98                 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
99                 [ ! -f /var/lock/subsys/$subsys ] && \
100                     [ ! -f /var/lock/subsys/${subsys}.init ] && continue
101
102                 # Bring the subsystem down.
103                 $i stop
104         done
105
106         # Now run the START scripts.
107         for i in /etc/rc.d/rc$runlevel.d/S*; do
108                 # Check if the script is there.
109                 [ ! -f $i ] && continue
110
111                 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
112                 [ "${1%.rpmsave}" != "${1}" ] && continue
113                 [ "${1%.rpmorig}" != "${1}" ] && continue
114                 [ "${1%.rpmnew}" != "${1}" ] && continue
115
116                 # Check if the subsystem is already up.
117                 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
118                 [ -f /var/lock/subsys/$subsys ] || \
119                     [ -f /var/lock/subsys/${subsys}.init ] && continue
120
121                 # Bring the subsystem up.
122                 $i start
123         done
124 fi
125
126 # if runlevel is 0 (halt) or 6 (reboot) run rc.shutdown
127 if [ "$runlevel" = "0" ] || [ "$runlevel" = "6" ]; then
128         /etc/rc.d/rc.shutdown
129         if [ "$runlevel" = "0" ] ; then
130                 show "The system is halted"; ok
131                 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
132                 eval halt -d
133         else
134                 show "Please stand by while rebooting the system"; ok
135                 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
136                 eval reboot -d
137         fi
138 else
139         if [ "$RUN_LDCONFIG" = "yes" ] ; then
140                 if [ -x /sbin/ldconfig ]; then
141                         run_cmd "Setting up /etc/ld.so.cache" /sbin/ldconfig -X
142                 fi
143         fi
144 fi
145
146 # Say something ;)
147 af2="`termput setaf 2`"
148 af7="`termput setaf 7`"
149 line="............................................................................"
150 text="`nls "%sResource Manager: %sRunlevel has been reached%s" $af2 $af7 $line`"
151 unset af2 af7 line
152 awk "BEGIN {printf \"%.78s\", \"$text\";}"
153 echo "`termput setaf 6`[`termput setaf 2` $runlevel `termput setaf 6`]`termput setaf 7`"
154
This page took 0.05389 seconds and 3 git commands to generate.