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.
Thanks
Bruce
#!/bin/bash
#
# 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, <miquels@drinkel.ow.org>
# Hacked to bits by Bruce Perens <Bruce@Pixar.com>
#
# Un-comment the following for debugging.
# debug=echo
# Source function library.
. /etc/init.d/functions
# Now find out what the current and what the previous runlevel are.
runlevel=$RUNLEVEL
# Get first argument. Set new runlevel to this argument.
[ "$1" != "" ] && runlevel=$1
previous=$PREVLEVEL
export runlevel previous
# Is there an rc directory for this new runlevel?
if [ -d /etc/rc$runlevel.d ]
then
avoid="" # A list of start scripts I don't have to run.
# First, run the KILL scripts.
if [ $previous != N ]
then
for i in /etc/rc$runlevel.d/K[0-9][0-9]*
do
# Check if the script is there.
[ ! -f $i ] && continue
suffix=${i#/etc/rc$runlevel.d/K[0-9][0-9]}
# 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
# files.
identical=0
start=/etc/rc$runlevel.d/S[0-9][0-9]$suffix
previous_start=/etc/rc$previous.d/S[0-9][0-9]$suffix
previous_stop=/etc/rc$previous.d/K[0-9][0-9]$suffix
if [ -f $previous_stop ] && [ $i -ef $previous_stop ]
then
identical=1
if [ -f $start ] || [ -f $previous_start ]
then
if [ ! -f $start ] \
|| [ ! -f $previous_start ] \
|| [ ! $start -ef $previous_start ]
then
identical=0
else
avoid=$avoid" "$start
fi
fi
fi
# Kill it.
[ $identical = 0 ] && $debug $i stop
done
fi
# Now run the START scripts for this runlevel.
for i in /etc/rc$runlevel.d/S*
do
identical=0
for j in $avoid
do
if [ $i = $j ]
then
identical=1
break
fi
done
if [ $identical = 0 ]
then
suffix=${i#/etc/rc$runlevel.d/S[0-9][0-9]}
previous_start=/etc/rc$previous.d/S[0-9][0-9]$suffix
stop=/etc/rc$runlevel.d/K[0-9][0-9]$suffix
if [ -f $previous_start ] \
&& [ $i -ef $previous_start ] \
&& [ ! -f $stop ]
then
identical=1
fi
fi
[ $identical = 0 ] && [ -f $i ] && $debug $i start
done
fi
# eof /etc/init.d/rc
Reply to: