for faster boot

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have tried to make the boot faster by staggering some processes in
background through an added service staggered.

--------------------------------------------------------------------
#/bin/bash
# PLACE: /root/bin/
# AUTHOR: vikram goyal <vikigoyal@xxxxxxxxx> 220407
#
# 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=11s
# 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
STAGGERED_SERVICES=' lm_sensors cups apcupsd ntpd clamav dovecot sendmail spamassassin smartd nasd jexec avahi-daemon wine '

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 
        # Switch off the service. We will manage it ourselves.
        /sbin/chkconfig $x off >> $STLOG 2>&1 &

        # DEBUGGING
        #echo "Processing: $x" >> $STLOG

        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
            # Some services start multiple instances like smartd
            # so restart is safer than start
            /sbin/service $x restart >> $STLOG 2>&1 &
            # return status is bogus :(
            # [ $? -eq 0 ] && sleep 15s || sleep 2s
            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
}

# ADD THE SERVICE IF THIS FILE IS EXECUTED FOR THE FIRST TIME
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ ! -f $SERVICEDIR/$SERVICENAME ]; then
cat >$SERVICEDIR/$SERVICENAME <<EOF
#!/bin/sh
#
# chkconfig:    2345 99 2
# description:  This is modification of boot process. It staggeres \\
#               the boot services mentioned in /root/bin/forfastboot

# Source function library.
. /etc/rc.d/init.d/functions

name='staggered'
exec='/root/bin/forfastboot'
prog="\`basename \$exec\`"
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
    ;;
    *)
        echo $"Usage: \$0 {start|stop}"
        exit 1
    ;;
esac

exit \$RETVAL
EOF
/bin/chmod +x $SERVICEDIR/$SERVICENAME
/sbin/chkconfig staggered on
echo service staggered added.
fi

if [ -n "`echo $1|egrep ^[0-9]{5\,}fb$`" ]; 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=${RANDOM}${RANDOM}fb
touch /tmp/$LF
$0 $LF &
exit
------------------------------------------------------------------------

If anyone cares to use it then please check the services I have added in
the staggered process before execution.

-- 
vikram...
         ||||||||
         ||||||||
^^'''''^^||root||^^^'''''''^^
        // \\   ))
       //(( \\// \\
      // /\\ ||   \\
     || / )) ((    \\
-- 
The core is not frozen, but slushy.
             -- Larry Wall in <199705101952.MAA00756@xxxxxxxx>
-- 
~|~
 =
Registered Linux User #285795


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux