source: projects/initscripts/tags/initscripts-8.91.0/rc.d/rc @ 1108

Revision 1108, 3.2 KB checked in by daisuke, 14 years ago (diff)

import initscripts-8.90.6 from internal cvs repository

Line 
1#!/bin/bash
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# Original Author:       
9#               Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
10#
11
12set -m
13
14# check a file to be a correct runlevel script
15check_runlevel ()
16{
17        # Check if the file exists at all.
18        [ -x "$1" ] || return 1
19        is_ignored_file "$1" && return 1
20        return 0
21}
22
23# Now find out what the current and what the previous runlevel are.
24argv1="$1"
25set `/sbin/runlevel`
26runlevel=$2
27previous=$1
28RUNLEVEL=$2
29PREVLEVEL=$1
30newrunlevel=$2
31progress=0
32export runlevel previous RUNLEVEL PREVLEVEL newrunlevel progress
33
34# Source function library.
35. /etc/init.d/functions
36
37# check if we use upstart
38UPSTART=
39[ -x /sbin/initctl ] && UPSTART=yes
40
41# initialize plymouth bootsplash
42initsplash
43[[ "$newrunlevel" = "0" || "$newrunlevel" = "6" ]] && \
44  [ "$splash_mode" = "plymouth" ] && \
45  rc_splash start $newrunlevel
46
47# See if we want to be in user confirmation mode
48if [ "$previous" = "N" ]; then
49    if grep -i confirm /proc/cmdline >/dev/null || [ -f /var/run/confirm ] ; then
50      rm -f /var/run/confirm
51      CONFIRM=yes
52      echo $"Entering interactive startup"
53    else
54      CONFIRM=
55      echo $"Entering non-interactive startup"
56    fi
57fi
58
59export CONFIRM
60
61# Get first argument. Set new runlevel to this argument.
62[ -n "$argv1" ] && runlevel="$argv1"
63
64# Is there an rc directory for this new runlevel?
65[ -d /etc/rc$runlevel.d ] || exit 0
66
67# First, run the KILL scripts.
68for i in /etc/rc$runlevel.d/K*; do
69        # Check if the subsystem is already up.
70        subsys=${i#/etc/rc$runlevel.d/K??}
71        [ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/${subsys}.init ] || continue
72        check_runlevel "$i" || continue
73
74        update_boot_stage "$subsys"
75        # Bring the subsystem down.
76        [ -n "$UPSTART" ] && initctl emit --quiet stopping JOB=$subsys
77        if egrep -q "(killproc |action )" $i ; then
78                $i stop
79        else
80                action $"Stopping $subsys: " $i stop
81        fi
82        [ -n "$UPSTART" ] && initctl emit --quiet stopped JOB=$subsys
83done
84
85# Now run the START scripts.
86for i in /etc/rc$runlevel.d/S*; do
87        # Check if the subsystem is already up.
88        subsys=${i#/etc/rc$runlevel.d/S??}
89        [ -f /var/lock/subsys/$subsys ] && continue
90        [ -f /var/lock/subsys/${subsys}.init ] && continue
91        check_runlevel "$i" || continue
92
93        # If we're in confirmation mode, get user confirmation
94        if [ -n "$CONFIRM" ]; then
95            confirm $subsys
96            rc=$?
97            if [ "$rc" = "1" ]; then
98                continue
99            elif [ "$rc" = "2" ]; then
100                CONFIRM=
101            fi
102        fi
103
104        update_boot_stage "$subsys"
105        # Bring the subsystem up.
106        [ -n "$UPSTART" ] && initctl emit --quiet starting JOB=$subsys
107        if egrep -q "(daemon |action )" $i ; then
108                if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then
109                        export LC_ALL=C
110                        exec $i start
111                else
112                    $i start
113                fi
114        else
115                if [ "$subsys" = "halt" -o "$subsys" = "reboot" -o "$subsys" = "single" -o "$subsys" = "local" ]; then
116                    if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then
117                        export LC_ALL=C
118                        exec $i start
119                    fi
120                    $i start
121                else
122                    action $"Starting $subsys: " $i start
123                fi
124        fi
125        [ -n "$UPSTART" ] && initctl emit --quiet started JOB=$subsys
126done
127
128exit 0
129   
Note: See TracBrowser for help on using the repository browser.