CCL Home Page
Up Directory CCL httpd.jkl.txt
#!/bin/sh
#
# Startup script for the Apache Web Server
# derived from the /etc/init.d/httpd script which came with RH7.0
# Modified dramatically by Jan Labanowski on 2001.01.26
#
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#	       HTML files and CGI.
# processname: httpd
# httpd pidfile: /var/run/httpd-jkl.pid
# tomcat pidfile: $TOMCAT_HOME/logs/tomcat.pid
# config: /etc/httpd/conf/access.conf
# config: /etc/httpd/conf/httpd.conf
# config: /etc/httpd/conf/srm.conf

JAKARTA_HOME=/usr/local/jakarta_3.2.1
TOMCAT_HOME=${JAKARTA_HOME}/jakarta-tomcat-3.2.1
export JAKARTA_HOME TOMCAT_HOME

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

# Path to the httpd binary.
httpd=/usr/sbin/httpd

# Until glibc's locale support is working right again, work around it.
LANG=C

# Change the major functions into functions.
moduleargs() {
	moduledir=/usr/lib/apache
	moduleargs=
	for module in ${moduledir}/*.so ; do
		if [ -x ${module} ] ; then
			module=`echo ${module} | awk '{\
				gsub(".*/","");\
				gsub("^mod_","");\
				gsub("^lib","");\
				gsub("\.so$","");\
				print toupper($0)}'`
			moduleargs="${moduleargs} -D HAVE_$module"
		fi
	done
	echo ${moduleargs}
}
start() {
	echo Starting Tomcat
        # check if tomcat.pid file exists [tomcat.sh creates it.]
        if [ -a  ${TOMCAT_HOME}/logs/tomcat.pid ] ; then
          pid=`cat ${TOMCAT_HOME}/logs/tomcat.pid`
          # check if process is still running
          if [ -d /proc/$pid ] ; then
            # get the process command line
            cmdline=`cat /proc/$pid/cmdline`
            # check if it is really Tomcat running, and not some other thing
            # which eventually took the process id after tomcat died ages ago
            if [ "${cmdline/*java*/java}" == "java" ] ; then
               echo Tomcat already running as process $pid. Stop it first...
               echo You can stop Tomcat by running:
               echo    apache_stop
               echo or log in as webrun and use kill command
               return 1
            fi
          fi 
          echo Warning: Tomcat was not shut down gracefully
          echo Removing file: ${TOMCAT_HOME}/logs/tomcat.pid
          rm -f ${TOMCAT_HOME}/logs/tomcat.pid
        fi

	su - webrun --command="echo ========START: $DATE =============== >>${TOMCAT_HOME}/logs/t3.2_jk 2>&1  " &
	su - webrun --command="nohup ${TOMCAT_HOME}/bin/startup.sh >>${TOMCAT_HOME}/logs/t3.2_jk 2>&1  " &
        echo Waiting 3 seconds for Tomcat to load
        sleep 3
	echo "Starting httpd"
        # if pid file for httpd exists
        if [ -a  /var/run/httpd-jkl.pid ] ; then
          pid=`cat /var/run/httpd-jkl.pid`
          if [ -d /proc/$pid ] ; then
            cmdline=`cat /proc/$pid/cmdline`
            # check if it is really Apache running, and not some other thing
            # which eventually took the process id after tomcat died ages ago
            if [ "${cmdline/*httpd*/httpd}" == "httpd" ] ; then
               echo Apache is already running as process $pid. Stop it first...
               echo You can stop Tomcat by running:
               echo    apache_stop
               return 1
            fi
          fi 
          echo Warning: Apache \(httpd\) was not shut down gracefully
          echo Removing file: /var/run/httpd-jkl.pid
          rm -f /var/run/httpd-jkl.pid
        fi
 
        # now, run apache, its httpd.conf puts pid in /var/run/httpd-jkl.pid
 	${httpd} `moduleargs` 
        sleep 2
        echo Apache \(i.e., httpd\) is now running as process: `cat /var/run/httpd-jkl.pid`
	return 0 
}
stop() {
	echo "Shutting down Apache (i.e., httpd): "
        if [ -a  /var/run/httpd-jkl.pid ] ; then
          pid=`cat /var/run/httpd-jkl.pid`
          if [ -d /proc/$pid ] ; then
            cmdline=`cat /proc/$pid/cmdline`
            if [ "${cmdline/*httpd*/httpd}" == "httpd" ] ; then
              kill $pid
              sleep 2
            else
              echo Apache was not shut down gracefully...
            fi
          fi
          # in case Apache did not clean up after itself.
          if [ -a  /var/run/httpd-jkl.pid ] ; then
            echo Apache was not shut down gracefully...
            rm -f /var/run/httpd-jkl.pid
          fi
        else
          echo Apache is not running...
        fi

	echo "Shutting down Tomcat: "
        if [ -a  ${TOMCAT_HOME}/logs/tomcat.pid ] ; then
          pid=`cat ${TOMCAT_HOME}/logs/tomcat.pid`
          if [ -d /proc/$pid ] ; then
            # get the process command line
            cmdline=`cat /proc/$pid/cmdline`
            # check if it is really Tomcat running, and not some other thing
            # which eventually took the process id after tomcat died ages ago
            if [ "${cmdline/*java*/java}" == "java" ] ; then
              su - webrun --command="echo ========STOP: $DATE =============== >>${TOMCAT_HOME}/logs/t3.2_jk 2>&1  " &
              su - webrun --command="nohup ${TOMCAT_HOME}/bin/shutdown.sh >>${TOMCAT_HOME}/logs/t3.2_jk 2>&1  " &
              return 0
            else
               echo Warning: Tomcat was not shut down gracefully
               return 0
            fi
          fi 
          echo Warning: Tomcat was not shut down gracefully
          echo file ${TOMCAT_HOME}/logs/tomcat.pid is removed
          rm -f ${TOMCAT_HOME}/logs/tomcat.pid
        else
          echo Tomcat is not running...
        fi
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  *)
	echo "Usage: $0 {start|stop|restart|reload|condrestart|status}"
	exit 1
esac

Modified: Fri Jan 26 21:32:52 2001 GMT
Page accessed 359 times since Tue Mar 15 13:18:24 2005 GMT