[1108] | 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 | |
---|
| 12 | set -m |
---|
| 13 | |
---|
| 14 | # check a file to be a correct runlevel script |
---|
| 15 | check_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. |
---|
| 24 | argv1="$1" |
---|
| 25 | set `/sbin/runlevel` |
---|
| 26 | runlevel=$2 |
---|
| 27 | previous=$1 |
---|
| 28 | RUNLEVEL=$2 |
---|
| 29 | PREVLEVEL=$1 |
---|
| 30 | newrunlevel=$2 |
---|
| 31 | progress=0 |
---|
| 32 | export runlevel previous RUNLEVEL PREVLEVEL newrunlevel progress |
---|
| 33 | |
---|
| 34 | # Source function library. |
---|
| 35 | . /etc/init.d/functions |
---|
| 36 | |
---|
| 37 | # check if we use upstart |
---|
| 38 | UPSTART= |
---|
| 39 | [ -x /sbin/initctl ] && UPSTART=yes |
---|
| 40 | |
---|
| 41 | # See if we want to be in user confirmation mode |
---|
| 42 | if [ "$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 |
---|
| 51 | fi |
---|
| 52 | |
---|
| 53 | export 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. |
---|
| 62 | for 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 |
---|
| 77 | done |
---|
| 78 | |
---|
| 79 | # Now run the START scripts. |
---|
| 80 | for 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 |
---|
| 120 | done |
---|
| 121 | |
---|
| 122 | exit 0 |
---|
| 123 | |
---|