initscripts/etc/rc.d/init.d/rc

172 lines
4.7 KiB
Bash
Executable File

#!/bin/sh
# rc - Main Run Level Control Script
#
# Copyright (c) 2003-2011 by Silvan Calarco <silvan.calarco@mambasoft.it>
# Copyright (c) 2003-2009,2011-2012 by Davide Madrisan <davide.madrisan@gmail.com>
. /etc/sysconfig/rc
if [ -r $rc_base/init.d/rc.embedded ]; then
. $rc_base/init.d/rc.embedded
exit 0
fi
. $rc_functions
[ -e /etc/locale.conf ] && . /etc/locale.conf || . /etc/sysconfig/i18n
LC_ALL=$LANG
TEXTDOMAIN=initscripts
TEXTDOMAINDIR=/usr/share/locale/
HOME="/root"; export HOME
trap "" INT QUIT TSTP
# detect kernel command line parameters
# $CMDLINE is exported from mkinitramfs
[ -z "$CMDLINE" ] && CMDLINE="`cat /proc/cmdline 2>/dev/null`"
debug=0
for cmd in $CMDLINE; do
case "$cmd" in
debug) debug=1 ;;
debug=*) debug=${cmd/debug=/} ;;
multithread=*) multithread=${cmd/multithread=/} ;;
esac
done
[ $debug -gt 0 ] && {
MAKEADD="DEBUG=1"
LOGFILE=/dev/console
}
# set current (new) and previous runlevels
runlevel=$1; export runlevel
previous=${PREVLEVEL:-N}
rex="[0-9][0-9]"
[ "$runlevel" ] ||
{ echo "Usage: $0 <runlevel>" >&2; exit 1; }
[ -d $rc_base/rc$runlevel.d ] ||
{ echo $"$rc_base/rc$runlevel.d does not exist" >&2; exit 1; }
[ "$previous" = "$runlevel" ] && exit 0
export RUNLEVEL
[ -e /run/plymouth/pid ] || {
# workaround for plymouthd stopping at runlevel change with non-KMS drivers
$PLYMOUTHD --attach-to-session --pid-file /run/plymouth/pid
$PLYMOUTH --show-splash
WORKAROUND=1
}
[ "$previous" != "N" ] && progressbase=10 || progressbase=65
if [ "$runlevel" = "0" -o "$runlevel" = "6" ]; then
$PLYMOUTHD --attach-to-session
$PLYMOUTH --show-splash
if [ "$runlevel" = "0" ]; then
$PLYMOUTH message --text=$"System shutting down, please wait..."
else
$PLYMOUTH message --text=$"System rebooting, please wait..."
fi
else
$PLYMOUTH message --text=$"Starting services..."
fi
allservicesnum=`ls -1 $rc_base/rc$runlevel.d/[S,K]* 2>/dev/null | wc -l`
if [ "$previous" != "N" ]; then
if [ "$multithread" = "1" ]; then
/bin/echo -e $"Stopping runlevel $runlevel services...""\r" >&2
make -C /var/init --no-print-directory -i -j -f /var/init/runlevel.mk \
JOB=stop \
PROGRESS_TOT=${allservicesnum} \
PROGRESS_BASE=${progressbase} \
ALLSERVICESNUM=$allservicesnum $MAKEADD
else
[ $debug -eq 0 ] && {
LOGFILE=/var/log/initd.$runlevel.stop
> $LOGFILE
}
i=0
for servicefile in `ls $rc_base/rc$runlevel.d/K* 2>/dev/null`; do
check_link $servicefile &&
{ service=${servicefile#$rc_base/rc$runlevel.d/K$rex}
prev_start=$rc_base/rc$previous.d/S$rex$service
sysinit_start=$rc_base/rcsysinit.d/S$rex$service
if [ "$runlevel" != "0" ] && [ "$runlevel" != "6" ]; then
[ ! -f $prev_start ] && [ ! -f $sysinit_start ] && continue
fi
progress=`expr $progressbase + $i \* \( 100 - $progressbase \) / ${allservicesnum}`
$servicefile stop >> $LOGFILE
i=`expr $i + 1`
}
done
[ "$progress" ] && progressbase=$progress
fi
fi
echo -e $"Starting runlevel $runlevel services...""\r"
if [ "$runlevel" == "5" -a "$previous" == "N" ]; then
[ -e /run/plymouth/pid ] && touch /var/spool/gdm/force-display-on-active-vt
else
rm -f /var/spool/gdm/force-display-on-active-vt
fi
if [ "$multithread" = "1" ]; then
# recreate multithreaded dependencies
depinit >/dev/null 2>&1
# now start multithreaded init
rm -f /var/lock/subsys/local
make -C /var/init --no-print-directory -i -j -k -f /var/init/runlevel.mk \
JOB=start \
PROGRESS_TOT=${allservicesnum} \
PROGRESS_BASE=${progressbase} \
$MAKEADD 2>/dev/null &
while [ ! -e /var/lock/subsys/local ]; do
[ "`jobs`" ] || break
sleep 1
done
else
[ $debug -eq 0 ] && {
LOGFILE=/var/log/initd.$runlevel.start
> $LOGFILE
}
i=0
for servicefile in `ls $rc_base/rc$runlevel.d/S* 2> /dev/null`; do
check_link $servicefile || { i=`expr $i + 1`; continue; }
if [ "$previous" != "N" ]; then
service=${servicefile#$rc_base/rc$runlevel.d/S$rex}
stop=$rc_base/rc$runlevel.d/K$rex$service
prev_start=$rc_base/rc$previous.d/S$rex$service
[ -f $prev_start ] && [ ! -f $stop ] && continue
fi
progress=`expr $progressbase + $i \* \( 100 - $progressbase \) / ${allservicesnum}`
$servicefile start >> $LOGFILE
i=`expr $i + 1`
done
fi
if [ ! "$runlevel" = "5" ]; then
chvt 1
$PLYMOUTH quit
else
$PLYMOUTH message --text=""
if [ "$WORKAROUND" ]; then
# FIXME: when plymouth crashes and is restarted above the ENTER key X restart bug
# comes back if not quit
$PLYMOUTH quit
fi
fi