Wednesday, April 16, 2014

Boot level script for apache webserver

Following steps will guide you setup the run level scritps to start and stop the Apache web server during the OS reboot.

Prepare a script to start and stop the server with "start" and "stop" as the input parameters to the script.

You can edit the following and customize it with your own paths.

#!/bin/sh

case "$1" in
'start')
        /apache/bin/httpd -k start
        ;;
'stop')
        /apache/bin/httpd -k stop
        ;;
*)
        echo "Usage: /etc/init.d/apache_start { start | stop }"
        ;;
esac

Name the above script as apache_start.

Place the apache_start in /etc/init.d folder

The run level scripts for apache have to be placed under rc0.d and rc3.d.

To get to know which run level is configured in your OS type the following command.

Who -r


This screen shot shows that 3 and 0 are the run levels for the OS.

Hence the /etc/rc3.d has to contain the startup script and /etc/rc0.d has to contain the stop script.

Navigate to /etc/rc3.d and create a softlink to the script in /etc/init.d, Repeat the same for /etc/rc0.d

Choose a sequence ex: for the start script S18apachestart and stop script K18apachestop.

Now, When ever the OS reboots, The apache will stop and start automatically.

Feel free to comment if you need any further help.

                                 (: Happy learning :)

0 comments:

Post a Comment