Please try this
The following is a replacement for /etc/init.d/rc with one added feature.
If the previous run-level has the exact same start and kill scripts for a
particular feature as the present run level, those scripts are _not_ run,
becuse there would be no change.
If you have the same scripts in runlevel 3 as you have in runlevel 4, you
should be able to switch between them without anything being started or
stopped. This should help the people who want to change just one or two
things when switching between these run levels without stopping all of the
telnet and FTP sessions, etc.
The files are compared by their inode/device numbers. If the files are
symbolic links to the same file or hard links, they will be treated as
the same. If they are copies of the same data in separate files, they
will be treated as different. The other alternative would have been to
actually compare the contents of the files, this would have been a bit
slower and would have rattled the disk more.
Save your old copy of the file before installing this. Be sure to make
it owned by root, mode 755.
# rc This file is responsible for starting/stopping
# services when the runlevel changes. It is also
# responsible for the very first setup of basic
# things, such as setting the hostname.
# Version: @(#) /etc/init.d/rc Debian 2.56-6 Thu Jul 27 21:05:01 PDT 1995
# Author: Miquel van Smoorenburg, <email@example.com>
# Hacked to bits by Bruce Perens <Bruce@Pixar.com>
# Un-comment the following for debugging.
# Source function library.
# Now find out what the current and what the previous runlevel are.
# Get first argument. Set new runlevel to this argument.
[ "$1" != "" ] && runlevel=$1
export runlevel previous
# Is there an rc directory for this new runlevel?
if [ -d /etc/rc$runlevel.d ]
avoid="" # A list of start scripts I don't have to run.
# First, run the KILL scripts.
if [ $previous != N ]
for i in /etc/rc$runlevel.d/K[0-9][0-9]*
# Check if the script is there.
[ ! -f $i ] && continue
# Generate the name of the start script corresponding
# to this stop script, the start script in the previous
# level, and the stop script in the previous level.
# Check these files, and see if the previous level's
# files are links to the ones for this level.
# If they are, this level treats this feature the same
# as the previous level, and I don't have to run these
if [ -f $previous_stop ] && [ $i -ef $previous_stop ]
if [ -f $start ] || [ -f $previous_start ]
if [ ! -f $start ] \
|| [ ! -f $previous_start ] \
|| [ ! $start -ef $previous_start ]
# Kill it.
[ $identical = 0 ] && $debug $i stop
# Now run the START scripts for this runlevel.
for i in /etc/rc$runlevel.d/S*
for j in $avoid
if [ $i = $j ]
if [ $identical = 0 ]
if [ -f $previous_start ] \
&& [ $i -ef $previous_start ] \
&& [ ! -f $stop ]
[ $identical = 0 ] && [ -f $i ] && $debug $i start
# eof /etc/init.d/rc