source: projects/initscripts/tags/initscripts-8.91.3/rc.d/rc @ 3072

Revision 3072, 3.1 KB checked in by daisuke, 13 years ago (diff)

tagging as initscripts-8.91.3

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# See if we want to be in user confirmation mode
42if [ "$previous" = "N" ]; then
43    if grep -i confirm /proc/cmdline >/dev/null || [ -f /var/run/confirm ] ; then
44      rm -f /var/run/confirm
45      CONFIRM=yes
46      echo $"Entering interactive startup"
47    else
48      CONFIRM=
49      echo $"Entering non-interactive startup"
50    fi
51fi
52
53export CONFIRM
54
55# Get first argument. Set new runlevel to this argument.
56[ -n "$argv1" ] && runlevel="$argv1"
57
58# Is there an rc directory for this new runlevel?
59[ -d /etc/rc$runlevel.d ] || exit 0
60
61# First, run the KILL scripts.
62for i in /etc/rc$runlevel.d/K*; do
63        # Check if the subsystem is already up.
64        subsys=${i#/etc/rc$runlevel.d/K??}
65        [ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/${subsys}.init ] || continue
66        check_runlevel "$i" || continue
67
68        update_boot_stage "$subsys"
69        # Bring the subsystem down.
70        [ -n "$UPSTART" ] && initctl emit --quiet stopping JOB=$subsys
71        if egrep -q "(killproc |action )" $i ; then
72                $i stop
73        else
74                action $"Stopping $subsys: " $i stop
75        fi
76        [ -n "$UPSTART" ] && initctl emit --quiet stopped JOB=$subsys
77done
78
79# Now run the START scripts.
80for i in /etc/rc$runlevel.d/S*; do
81        # Check if the subsystem is already up.
82        subsys=${i#/etc/rc$runlevel.d/S??}
83        [ -f /var/lock/subsys/$subsys ] && continue
84        [ -f /var/lock/subsys/${subsys}.init ] && continue
85        check_runlevel "$i" || continue
86
87        # If we're in confirmation mode, get user confirmation
88        if [ -n "$CONFIRM" ]; then
89            confirm $subsys
90            rc=$?
91            if [ "$rc" = "1" ]; then
92                continue
93            elif [ "$rc" = "2" ]; then
94                CONFIRM=
95            fi
96        fi
97
98        update_boot_stage "$subsys"
99        # Bring the subsystem up.
100        [ -n "$UPSTART" ] && initctl emit --quiet starting JOB=$subsys
101        if egrep -q "(daemon |action )" $i ; then
102                if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then
103                        export LC_ALL=C
104                        exec $i start
105                else
106                    $i start
107                fi
108        else
109                if [ "$subsys" = "halt" -o "$subsys" = "reboot" -o "$subsys" = "single" -o "$subsys" = "local" ]; then
110                    if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then
111                        export LC_ALL=C
112                        exec $i start
113                    fi
114                    $i start
115                else
116                    action $"Starting $subsys: " $i start
117                fi
118        fi
119        [ -n "$UPSTART" ] && initctl emit --quiet started JOB=$subsys
120done
121
122exit 0
123   
Note: See TracBrowser for help on using the repository browser.