2011-04-26 12:26:24 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# rc - Main Run Level Control Script
|
|
|
|
#
|
|
|
|
# Copyright (c) 2003-2011 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
2012-01-19 20:23:54 +01:00
|
|
|
# Copyright (c) 2003-2009,2011-2012 by Davide Madrisan <davide.madrisan@gmail.com>
|
2011-04-26 12:26:24 +02:00
|
|
|
|
|
|
|
. /etc/sysconfig/rc
|
|
|
|
|
|
|
|
if [ -r $rc_base/init.d/rc.embedded ]; then
|
|
|
|
. $rc_base/init.d/rc.embedded
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
. $rc_functions
|
2011-09-01 13:59:50 +02:00
|
|
|
[ -e /etc/locale.conf ] && . /etc/locale.conf || . /etc/sysconfig/i18n
|
2011-04-26 12:26:24 +02:00
|
|
|
|
|
|
|
LC_ALL=$LANG
|
|
|
|
TEXTDOMAIN=initscripts
|
|
|
|
TEXTDOMAINDIR=/usr/share/locale/
|
|
|
|
|
|
|
|
HOME="/root"; export HOME
|
|
|
|
|
2012-01-19 20:23:54 +01:00
|
|
|
trap "" INT QUIT TSTP
|
2011-04-26 12:26:24 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2011-12-02 14:47:48 +01:00
|
|
|
[ $debug -gt 0 ] && {
|
|
|
|
MAKEADD="DEBUG=1"
|
|
|
|
LOGFILE=/dev/console
|
|
|
|
}
|
2011-04-26 12:26:24 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2011-10-21 19:13:48 +02:00
|
|
|
[ -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
|
2011-12-26 14:07:12 +01:00
|
|
|
WORKAROUND=1
|
2011-10-21 19:13:48 +02:00
|
|
|
}
|
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
[ "$previous" != "N" ] && progressbase=10 || progressbase=65
|
|
|
|
|
|
|
|
if [ "$runlevel" = "0" -o "$runlevel" = "6" ]; then
|
2011-06-30 14:10:01 +02:00
|
|
|
$PLYMOUTHD --attach-to-session
|
|
|
|
$PLYMOUTH --show-splash
|
2011-04-26 12:26:24 +02:00
|
|
|
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
|
2011-12-02 14:47:48 +01:00
|
|
|
[ $debug -eq 0 ] && {
|
|
|
|
LOGFILE=/var/log/initd.$runlevel.stop
|
|
|
|
> $LOGFILE
|
|
|
|
}
|
2011-04-26 12:26:24 +02:00
|
|
|
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}`
|
2011-12-02 14:47:48 +01:00
|
|
|
$servicefile stop >> $LOGFILE
|
2011-04-26 12:26:24 +02:00
|
|
|
i=`expr $i + 1`
|
|
|
|
}
|
|
|
|
done
|
|
|
|
[ "$progress" ] && progressbase=$progress
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-11-29 01:34:02 +01:00
|
|
|
echo -e $"Starting runlevel $runlevel services...""\r"
|
|
|
|
|
2012-03-08 15:31:01 +01:00
|
|
|
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
|
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
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
|
2011-12-02 14:47:48 +01:00
|
|
|
[ $debug -eq 0 ] && {
|
|
|
|
LOGFILE=/var/log/initd.$runlevel.start
|
|
|
|
> $LOGFILE
|
|
|
|
}
|
2011-04-26 12:26:24 +02:00
|
|
|
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}`
|
2011-12-02 14:47:48 +01:00
|
|
|
$servicefile start >> $LOGFILE
|
2011-04-26 12:26:24 +02:00
|
|
|
i=`expr $i + 1`
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2011-06-22 23:22:56 +02:00
|
|
|
if [ ! "$runlevel" = "5" ]; then
|
2011-06-09 14:46:52 +02:00
|
|
|
chvt 1
|
|
|
|
$PLYMOUTH quit
|
2011-11-29 01:34:02 +01:00
|
|
|
else
|
2011-11-29 01:56:50 +01:00
|
|
|
$PLYMOUTH message --text=""
|
2011-12-26 14:07:12 +01:00
|
|
|
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
|
2011-06-09 14:46:52 +02:00
|
|
|
fi
|