for faster boot
Vikram Goyal
vikigoyal at gmail.com
Mon Apr 23 16:36:39 UTC 2007
On Mon, Apr 23, 2007 at 11:08:27AM +0930, Tim wrote:
> On Sun, 2007-04-22 at 17:43 +0530, Vikram Goyal wrote:
> > I have tried to make the boot faster by staggering some processes in
> > background through an added service staggered.
>
> I seem to recall reading that there was a move to load some start-up
> services concurrently rather than consecutively, but I hadn't noticed it
> being done anywhere. Is this better than the readahead_early and
> readahead_later services that come with FC6?
>
readahead_* services are for file caching. and do not load the services in
the background to let the booting go faster as far as I know.
Recently the clamav package had a change and it was taking about a min
to load stalling the rest of the boot. I got irritated and put it in
/etc/rc.local. Then I thought of putting such services in a script but I
had to switch them off to stall them from loading at boot from init
scripts. Things got a bit complicated so I wrote this script.
To manage this kind of booting I had to create a service staggered.
I have rewritten what I had posted earlier, and I presume it is much
better than the last one. Since I wrote it initially for myself but can
be used in a general way also so I thought of sharing it.
The script forfastboot must be in /root/bin/
Once executed manually from there it creates two files:
/etc/init.d/staggered
/etc/sysconfig/staggered
and adds service staggered.
>From then on the service staggered manages the services mentioned in
/etc/sysconfig/staggered
I have included only clamav and ntpd services to be staggered
and the rest are in the excluded list for people to test and see
whats happening. The services in the excluded list are not affected.
If you are comfortable with it then you may include other services also
If file /etc/sysconfig/staggered gets corrupted while editing, delete it
and a new default one will be created by the service itself.
previous one is obsolete.
posting the new file below.
save this file as forfastboot in /root/bin/
-----------------------------------------------------------------------
#/bin/bash
# NAME: forfastboot
# PLACE: /root/bin/
# AUTHOR: vikram goyal <vikigoyal at gmail.com> 230407
#
# The file is to be called as:
# The first time call is the filename itself and then its through service call
#
# service staggered start
#
# So that these services load up in the background & save boot time
#
[ -z "$STLOG" ] && STLOG=/dev/tty
# DEBUGGING
#echo \$1=$1 >> $STLOG
SERVICEDIR=/etc/init.d
SERVICENAME=staggered
STAGGERTIME=7s
addchkserv()
{
# ADD/CHK THE SERVICE
# ~~~~~~~~~~~~~~~~~~~
# If service file has changed copy the new one. If it does not
# exist yet make a new one.
if [ -f $SERVICEDIR/$SERVICENAME ]; then
fchk=`mktemp`
createserv $fchk
[ -n "`diff $fchk $SERVICEDIR/$SERVICENAME`" ] && \
/sbin/chkconfig --del staggered && \
mv -f $fchk $SERVICEDIR/$SERVICENAME
setperms
else
createserv $SERVICEDIR/$SERVICENAME
echo service staggered added.
setperms
fi
}
addservnames()
{
# Add the sample file staggered services names list in /etc/sysconfig
servicesnames=`cat /etc/init.d/staggered|grep servicesnames=|cut -d = -f2`
if [ ! -f $servicesnames ]; then
eval cat >$servicesnames <<EOF
#
# The services mentioned here should be in the right priority
# as mentioned in chkconfig.
#
# In general no service should be here below around 25 start priority
#
# This is the list of services which one may want to stagger now
# or in future. So include any service which you want staggerd.
#
STAGGERED_SERVICES=' lm_sensors cups apcupsd ntpd clamav dovecot sendmail spamassassin smartd nasd jexec avahi-daemon wine '
#
# This is the services list which tells staggerd to stay away.
#
# 1} Service may not be in use at the moment.
# 2} Temporarily you may want it out of staggered.
#
# NOTE: One must switch on the service if it was staggered but
# has been excluded and you want to use it.
#
EXCLUDE=' lm_sensors cups apcupsd dovecot sendmail spamassassin smartd nasd jexec avahi-daemon wine '
EOF
echo $servicesnames was created. >> $STLOG
fi
}
setperms()
{
/bin/chmod +x $SERVICEDIR/$SERVICENAME
/sbin/chkconfig staggered on
}
createserv()
{
# Create service file in /etc/init.d/
eval cat >$1 <<EOF
#!/bin/sh
#
# chkconfig: 2345 99 2
# description: This is modification of boot process. It staggeres \\
# the boot services mentioned in /etc/sysconfig/staggered
# Source function library.
. /etc/rc.d/init.d/functions
[ -f /etc/sysconfig/staggered ] && \
export servicesnames=/etc/sysconfig/staggered
name='staggered'
exec='/root/bin/forfastboot'
lockfile="/var/lock/subsys/\$name"
# Hash STLOG for debug output on console
export STLOG=/var/log/staggered.log
RETVAL=0
start() {
echo -n \$"Starting service staggered: "
#if [ -f \$lockfile ]; then
# echo_failure
# echo
# return
#fi
\$exec servicecall & > /dev/null 2>&1
#touch \$lockfile
echo_success && echo
}
stop() {
echo -n \$"Stopping service staggered: "
#rm -f \$lockfile
echo_success && echo
}
case "\$1" in
start|stop)
\$1
;;
restart)
stop
start
;;
*)
echo $"Usage: \$0 {start|stop|restart}"
exit 1
;;
esac
exit \$RETVAL
EOF
}
START ()
{
FN="$1"
R=`/sbin/runlevel|cut -d ' ' -f2`
echo -e "\n\t`date`\nSTART:" >> $STLOG
# DEBUGGING
#echo \$R=$R >> $STLOG
for x in $STAGGERED_SERVICES
do
[ ! -f $SERVICEDIR/$x ] && echo "error: file $SERVICEDIR/$x not found" >> $STLOG && continue
[ -n "$EXCLUDE" ] && \
[ -n "`echo $EXCLUDE|grep -w $x`" ] && echo "service $x in exclude list" >> $STLOG && continue
# Switch off the service. We will manage it ourselves.
/sbin/chkconfig $x off >> $STLOG 2>&1 &
unset C
C=`cat $SERVICEDIR/$x|grep chkconfig|tr '[ ]' '[:]'|tr -s '[:]'|cut -d ":" -f3|grep [\-$R]`
# DEBUGGING
#echo \$C=$C \$R=$R >> $STLOG
# Since the service x has been turned off. Check if it is supposed
# to run in this level. If yes start it.
if [ -n "$C" ]; then
if [ -n "`echo $C|grep \-`" -a -z "`echo $R|grep [2345]`" ]; then
echo "$R not one of 2,3,4,5 :$x not started" >> $STLOG
continue
fi
/sbin/service $x status >> $STLOG 2>&1 && continue
[ $? -gt 0 ] && \
/sbin/service $x start >> $STLOG 2>&1 && \
sleep $STAGGERTIME
else
echo "error: $x not to start in $R" >> $STLOG
fi
done
rm -f "/tmp/$FN"
echo -e "\n\t`date`\nEND:" >> $STLOG
}
if [ -n "$servicesnames" ]; then
. $servicesnames
else
# Not called from service file. It may not exist yet.
addchkserv
addservnames
fi
if [ -f "$1" ]; then
# Tmp lock file has been created, so call the function.
# DEBUGGING
#echo "loop \$1=$1 exe" >> $STLOG
START $1
exit 0
elif [ "$1" != servicecall ]; then
echo "call $0 from service staggered."
exit 1
fi
LF=`mktemp`
touch "$LF" || exit 1
$0 "$LF" &
exit
-----------------------------------------------------------------------
I have checked it and it's working fine at my end.
Thanks!
--
vikram...
||||||||
||||||||
^^'''''^^||root||^^^'''''''^^
// \\ ))
//(( \\// \\
// /\\ || \\
|| / )) (( \\
--
Maybe we could paint GOLDIE HAWN a rich PRUSSIAN BLUE --
--
O
~|~
=
Registered Linux User #285795
More information about the fedora-list
mailing list