:: [linux] How to set up system initialization scripts in RH 8.0 ::
HOME


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

[linux] How to set up system initialization scripts in RH 8.0


 
When an RH 8.0 system boots up, it goes through many stages. You can find a good reference to the boot process of RH 8.0 here. I will describe what happens when the boot process reaches a stage where it runs the init process.
The init process first runs the /etc/rc.d/rc.sysinit script. Basically, rc.sysinit takes care of everything that your system needs to have done at system initialization. For example, most systems use a clock, so on them rc.sysinit reads the /etc/sysconfig/clock configuration file to initialize the clock.
 
The init command then runs the /etc/inittab script, which runs the system at a default runlevel (usually 5).
The init program starts all of the background processes by looking in the appropriate rc directory for the runlevel specified as default in /etc/inittab. The rc directories are numbered to corresponds to the runlevel they represent. For instance, /etc/rc.d/rc5.d/ is the directory for runlevel five. When booting to runlevel 5, the init program looks in the /etc/rc.d/rc5.d/ directory to determine which processes to start and stop.There are many such scripts in this directory, which are actually links to /etc/rc.d/init.d. Some of them start with the capital letter "K" (Called K-Scripts) and some start with "S" (called Start-scripts). The init command first stops all of the K symbolic links in the directory by issuing the /etc/rc.d/init.d/<command> stop command, where <command> is the process to be killed. It then starts all of the S symbolic links by issuing /etc/rc.d/init.d/<command> start.
Below I present the S-script that i copied for DHCPD. This should serve as a general template in future

#!/bin/bash
#
#       /etc/rc.d/init.d/dhcpd
#
# Starts the dhcpd daemon
#
# description: Runs the DHCPd on eth1 (The private Network).
# processname: dhcpd
# Source function library.
. /etc/init.d/functions

test -x /usr/sbin/dhcpd || exit 0

RETVAL=0

#
#       See how we were called.
#

prog="dhcpd"

start() {
        # Check if dhcpd is already running
        if [ ! -f /var/lock/subsys/dhcpd ]; then
            echo -n $"Starting $prog: "
            daemon /usr/sbin/dhcpd eth1
            RETVAL=$?
            [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd
            echo
        fi
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        killproc /usr/sbin/dhcpd
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dhcpd
        echo
        return $RETVAL
}


restart() {
        stop
        start
}

reload() {
        restart
}

status_at() {
        status /usr/sbin/dhcpd
}

case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload|restart)
        restart
        ;;
condrestart)
        if [ -f /var/lock/subsys/dhcpd ]; then
            restart
        fi
        ;;
status)
        status_at
        ;;
*)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        exit 1
esac

exit $?
exit $RETVAL

 
Regards
Shashank
http://mia.ece.uic.edu/~papers