]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc
- send messages to /dev/console (which can be serial console) instead of virtual...
[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.15 1999/12/30 12:11:37 jajcus 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 # Now find out what the current and what the previous runlevel are.
34 argv1="$1"
35 set `/sbin/runlevel`
36 runlevel=$2
37 previous=$1
38 export runlevel previous
39
40 # if runlevel is 0 (halt) or 6 (reboot) change to first
41 # virtual console, and send messages to /dev/console 
42 # (it can be serial console too) 
43 if [ "$runlevel" = "0" ] || [ "$runlevel" = "6" ]; then
44         [ -x /usr/bin/chvt ] && /usr/bin/chvt 1 && echo
45         exec 0<> /dev/console 1>&0 2>&0
46 else
47 # if previous runlevel = current runlevel do nothing
48         [ "$runlevel" = "$previous" ] && exit 0
49 fi
50
51 # set onlcr to avoid staircase effect and do not lock scrolling
52 stty onlcr -ixon 0>&1
53
54 # Get first argument. Set new runlevel to this argument.
55 [ "$1" != "" ] && runlevel="$argv1"
56
57 # Tell linuxconf what runlevel we are in
58 [ -d /var/run -a -w /var/run ] && echo "/etc/rc.d/rc$runlevel.d" > /var/run/runlevel.dir
59
60
61 # Say something ;)
62 af2="`termput setaf 2`"
63 af7="`termput setaf 7`"
64 line="............................................................................"
65 text="`nls "%sResource Manager: %sEntering runlevel number%s" $af2 $af7 $line`"
66 unset af2 af7 line
67 awk "BEGIN {printf \"%.78s\", \"$text\";}"
68 echo "`termput setaf 6`[`termput setaf 2` $runlevel `termput setaf 6`]`termput setaf 7`"
69
70 # Is there an rc directory for this new runlevel?
71 if [ -d /etc/rc.d/rc$runlevel.d ]; then
72         # First, run the KILL scripts.
73         for i in /etc/rc.d/rc$runlevel.d/K*; do
74                 # Check if the script is there.
75                 [ ! -f $i ] && continue
76
77                 # Don't run [KS]??foo.{rpmsave,rpmorig,rpmnew} scripts
78                 [ "${1%.rpmsave}" != "${1}" ] && continue
79                 [ "${1%.rpmorig}" != "${1}" ] && continue
80                 [ "${1%.rpmnew}" != "${1}" ] && continue
81
82                 # Check if the subsystem is already up.
83                 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
84                 [ ! -f /var/lock/subsys/$subsys ] && \
85                     [ ! -f /var/lock/subsys/${subsys}.init ] && continue
86
87                 # Bring the subsystem down.
88                 $i stop
89         done
90
91         # Now run the START scripts.
92         for i in /etc/rc.d/rc$runlevel.d/S*; do
93                 # Check if the script is there.
94                 [ ! -f $i ] && continue
95
96                 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
97                 [ "${1%.rpmsave}" != "${1}" ] && continue
98                 [ "${1%.rpmorig}" != "${1}" ] && continue
99                 [ "${1%.rpmnew}" != "${1}" ] && continue
100
101                 # Check if the subsystem is already up.
102                 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
103                 [ -f /var/lock/subsys/$subsys ] || \
104                     [ -f /var/lock/subsys/${subsys}.init ] && continue
105
106                 # Bring the subsystem up.
107                 $i start
108         done
109 fi
110
111 # if runlevel is 0 (halt) or 6 (reboot) run rc.shutdown
112 if [ "$runlevel" = "0" ] || [ "$runlevel" = "6" ]; then
113         /etc/rc.d/rc.shutdown
114         if [ "$runlevel" = "0" ] ; then
115                 show "The system is halted"; ok
116                 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
117                 eval halt -d
118         else
119                 show "Please stand by while rebooting the system"; ok
120                 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
121                 eval reboot -d
122         fi
123 else
124         if [ -x /sbin/ldconfig ]; then
125                 run_cmd "Setting up /etc/ld.so.cache" /sbin/ldconfig -X
126         fi
127 fi
128
129 # Say something ;)
130 af2="`termput setaf 2`"
131 af7="`termput setaf 7`"
132 line="............................................................................"
133 text="`nls "%sResource Manager: %sRunlevel has been reached%s" $af2 $af7 $line`"
134 unset af2 af7 line
135 awk "BEGIN {printf \"%.78s\", \"$text\";}"
136 echo "`termput setaf 6`[`termput setaf 2` $runlevel `termput setaf 6`]`termput setaf 7`"
137
This page took 0.057271 seconds and 4 git commands to generate.