]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc
- version up to 0.0.9
[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.9 1999/08/31 23:12:44 wiget 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 ] && echo "/etc/rc.d/rc$runlevel.d" > /var/run/runlevel.dir
58
59
60 # Say something ;)
61 text="`termput setaf 2``nls "Resource Manager:"``termput setaf 7` `nls "Leaving runlevel number"`............................................................................"
62 awk "BEGIN {printf \"%.78s\", \"$text\";}"
63 echo "`termput setaf 6`[`termput setaf 2` $runlevel `termput setaf 6`]`termput setaf 7`"
64
65 # Is there an rc directory for this new runlevel?
66 if [ -d /etc/rc.d/rc$runlevel.d ]; then
67         # First, run the KILL scripts.
68         for i in /etc/rc.d/rc$runlevel.d/K*; do
69                 # Check if the script is there.
70                 [ ! -f $i ] && continue
71
72                 # Don't run [KS]??foo.{rpmsave,rpmorig,rpmnew} scripts
73                 [ "${1%.rpmsave}" != "${1}" ] && continue
74                 [ "${1%.rpmorig}" != "${1}" ] && continue
75                 [ "${1%.rpmnew}" != "${1}" ] && continue
76
77                 # Check if the subsystem is already up.
78                 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
79                 [ ! -f /var/lock/subsys/$subsys ] && \
80                     [ ! -f /var/lock/subsys/${subsys}.init ] && continue
81
82                 # Bring the subsystem down.
83                 $i stop
84         done
85
86         # Now run the START scripts.
87         for i in /etc/rc.d/rc$runlevel.d/S*; do
88                 # Check if the script is there.
89                 [ ! -f $i ] && continue
90
91                 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
92                 [ "${1%.rpmsave}" != "${1}" ] && continue
93                 [ "${1%.rpmorig}" != "${1}" ] && continue
94                 [ "${1%.rpmnew}" != "${1}" ] && continue
95
96                 # Check if the subsystem is already up.
97                 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
98                 [ -f /var/lock/subsys/$subsys ] || \
99                     [ -f /var/lock/subsys/${subsys}.init ] && continue
100
101                 # Bring the subsystem up.
102                 $i start
103         done
104 fi
105
106 # Say something ;)
107 text="`termput setaf 2``nls "Resource Manager:"``termput setaf 7` `nls "Runlevel has been reached"`............................................................................"
108 awk "BEGIN {printf \"%.78s\", \"$text\";}"
109 echo "`termput setaf 6`[`termput setaf 2` $runlevel `termput setaf 6`]`termput setaf 7`"
110
This page took 0.041242 seconds and 4 git commands to generate.