]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc
- fix: print "Entering" instead "Leaving" on entering in runlevel.
[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.12 1999/09/28 14:24:23 kloczek 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
42 if [ "$runlevel" == "0" ] || [ "$runlevel" == "6" ]; then
43         exec 0<> /dev/tty1 1>&0 2>&0
44         [ -x /usr/bin/chvt ] && /usr/bin/chvt 1 && echo
45 else
46 # if previous runlevel == current runlevel do nothing
47         [ "$runlevel" == "$previous" ] && exit 0
48 fi
49
50 # set onlcr to avoid staircase effect and do not lock scrolling
51 stty onlcr -ixon 0>&1
52
53 # Get first argument. Set new runlevel to this argument.
54 [ "$1" != "" ] && runlevel="$argv1"
55
56 # Tell linuxconf what runlevel we are in
57 [ -d /var/run -a -w /var/run ] && echo "/etc/rc.d/rc$runlevel.d" > /var/run/runlevel.dir
58
59
60 # Say something ;)
61 af2="`termput setaf 2`"
62 af7="`termput setaf 7`"
63 line="............................................................................"
64 text="`nls "%sResource Manager: %sEntering runlevel number%s" $af2 $af7 $line`"
65 unset af2 af7 line
66 awk "BEGIN {printf \"%.78s\", \"$text\";}"
67 echo "`termput setaf 6`[`termput setaf 2` $runlevel `termput setaf 6`]`termput setaf 7`"
68
69 # Is there an rc directory for this new runlevel?
70 if [ -d /etc/rc.d/rc$runlevel.d ]; then
71         # First, run the KILL scripts.
72         for i in /etc/rc.d/rc$runlevel.d/K*; do
73                 # Check if the script is there.
74                 [ ! -f $i ] && continue
75
76                 # Don't run [KS]??foo.{rpmsave,rpmorig,rpmnew} scripts
77                 [ "${1%.rpmsave}" != "${1}" ] && continue
78                 [ "${1%.rpmorig}" != "${1}" ] && continue
79                 [ "${1%.rpmnew}" != "${1}" ] && continue
80
81                 # Check if the subsystem is already up.
82                 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
83                 [ ! -f /var/lock/subsys/$subsys ] && \
84                     [ ! -f /var/lock/subsys/${subsys}.init ] && continue
85
86                 # Bring the subsystem down.
87                 $i stop
88         done
89
90         # Now run the START scripts.
91         for i in /etc/rc.d/rc$runlevel.d/S*; do
92                 # Check if the script is there.
93                 [ ! -f $i ] && continue
94
95                 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
96                 [ "${1%.rpmsave}" != "${1}" ] && continue
97                 [ "${1%.rpmorig}" != "${1}" ] && continue
98                 [ "${1%.rpmnew}" != "${1}" ] && continue
99
100                 # Check if the subsystem is already up.
101                 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
102                 [ -f /var/lock/subsys/$subsys ] || \
103                     [ -f /var/lock/subsys/${subsys}.init ] && continue
104
105                 # Bring the subsystem up.
106                 $i start
107         done
108 fi
109
110 # Say something ;)
111 af2="`termput setaf 2`"
112 af7="`termput setaf 7`"
113 line="............................................................................"
114 text="`nls "%sResource Manager: %sRunlevel has been reached%s" $af2 $af7 $line`"
115 unset af2 af7 line
116 awk "BEGIN {printf \"%.78s\", \"$text\";}"
117 echo "`termput setaf 6`[`termput setaf 2` $runlevel `termput setaf 6`]`termput setaf 7`"
118
This page took 0.049846 seconds and 4 git commands to generate.