#!/bin/sh # # Startup script for the Apache Web Server # # chkconfig: 345 92 8 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd # pidfile: /var/run/httpd.pid # Source function library. . /etc/rc.d/init.d/functions # Change the major functions into functions. moduleargs() { moduleargs= for module in $1/*.so ; do if [ -x ${module} ] ; then module=`echo ${module} | awk '{ gsub(".*/",""); gsub("^mod_",""); gsub("^lib",""); gsub(".so$",""); print toupper($0)}'` moduleargs="${moduleargs} -DHAVE_$module" fi done echo ${moduleargs} } # Get the extra modules so only the main server gets them extramoduleargs() { extramoduleargs= for extramodule in $1/*.so ; do if [ -x ${extramodule} ] ; then extramodule=`echo ${extramodule} | awk '{ gsub(".*/",""); gsub("^mod_",""); gsub("^lib",""); gsub(".so$",""); print toupper($0)}'` extramoduleargs="${extramoduleargs} -DHAVE_$extramodule" fi done echo ${extramoduleargs} } unset LS_COLORS KDE_DISPLAY BROWSER HELP_BROWSER GTK_RC_FILES XMODIFIERS unset COLORTERM DISPLAY LOGNAME SESSION_MANAGER KDE_INITIAL_DESKTOP unset TERM HOME USERNAME PWD ENV USER SSH_CLIENT MAIL SSH_TTY unset QT_XFT GDK_USE_XFT SECURE_LEVEL HISTCONTROL LESSOPEN unset TMP TMPDIR ### Hack for Status LYNX="lynx -dump" STATUSURL="http://localhost/server-status" STATUSURLPERL="http://localhost:8200/server-status" ## Number of times to try to start Apache in case of error #times_start="1 2 3" times_start="1" sleep_time="1 2 3 4 5" #Start with defaults SBIN=/usr/sbin CONF=/etc/httpd/conf HTTPD=httpd HTTPDPID=/var/run/httpd.pid HTTPDPERL=httpd-perl HTTPDPERLPID=/var/run/httpd-perl.pid #Directory where 1.3 configuration files reside, in case #someone installs 2.0, and later decides to install 1.3 on top #of it COMPAT=/usr/share/ADVX/compat # NOTE: detect/detectlib must be call before any use of $LIB ! detectlib() { local httpd=$1 local is_64bit_httpd=no #dd if=$httpd bs=1 count=4 skip=1 2> /dev/null | \ # tr '[\001-\011]' '[0-9]' | grep -q 'ELF1' && \ # is_64bit_httpd=yes case `/usr/bin/file $httpd` in *"ELF 64"*) is_64bit_httpd=yes ;; esac LIB="lib" case `uname -m`:$is_64bit_httpd in powerpc64:yes | s390x:yes | sparc64:yes | x86_64:yes) LIB="lib64";; esac } detect() { #### Find out if any version of Apache 2.0 is installed #### if [ -x $SBIN/httpd2-perl ]; then detectlib $SBIN/httpd2-perl MSGPERL="Apache 2.0/mod_perl" HTTPDPERL=httpd2-perl PERLFILE="-f $CONF/httpd2-perl.conf" PERLXMODS="-DAPACHE2 `extramoduleargs /usr/$LIB/apache2-extramodules`" PERLREGMODS=`moduleargs /usr/$LIB/apache2` elif [ -x $SBIN/httpd-perl ]; then detectlib $SBIN/httpd-perl MSGPERL="Apache 1.3/mod_perl" if [ ! -e /etc/httpd/modules ];then gprintf "Re-creating /etc/httpd/modules\n" pushd /etc/httpd>/dev/null ln -sf ../../usr/$LIB/apache modules popd >/dev/null fi if [ ! -e /etc/httpd/extramodules ];then gprintf "Re-creating /etc/httpd/extramodules\n" pushd /etc/httpd >/dev/null ln -sf ../../usr/$LIB/apache-extramodules extramodules popd >/dev/null fi if [ ! -e $CONF/httpd-perl.conf -a -e $CONF/httpd-perl.conf.rpmsave ];then gprintf "Recreating httpd-perl.conf from backup file\n" mv $CONF/httpd-perl.conf.rpmsave $CONF/httpd-perl.conf fi if [ ! -e $CONF/httpd-perl.conf -a -e $COMPAT/httpd-perl.conf ];then gprintf "Recreating httpd-perl.conf from compat file\n" rm -f $CONF/httpd-perl.conf cp $COMPAT/httpd-perl.conf $CONF/httpd-perl.conf fi HTTPDPERL=httpd-perl PERLFILE="-f $CONF/httpd-perl.conf" PERLXMODS=`extramoduleargs /usr/$LIB/apache-extramodules` PERLREGMODS=`moduleargs /usr/$LIB/apache` fi if [ ! -x $SBIN/httpd -a -e $CONF/RUN1.3 ];then gprintf "Apache 1.3 not present, removing %s/RUN1.3\n" "$CONF" rm -f $CONF/RUN1.3 fi if [ -x $SBIN/httpd2 -a ! -e $CONF/RUN1.3 ]; then detectlib $SBIN/httpd2 MSG="Apache 2.0" HTTPD=httpd2 HTTPDCONF="-f $CONF/httpd2.conf" APACHEXMODS="-DAPACHE2 `extramoduleargs /etc/httpd/2.0/extramodules`" APACHEREGMODS=`moduleargs /etc/httpd/2.0/modules` elif [ -x $SBIN/httpd ]; then detectlib $SBIN/httpd MSG="Apache 1.3" if [ ! -e /etc/httpd/modules ];then gprintf "Re-creating /etc/httpd/modules\n" pushd /etc/httpd >/dev/null ln -sf ../../usr/$LIB/apache modules popd >/dev/null fi if [ ! -e /etc/httpd/extramodules ];then gprintf "Re-creating /etc/httpd/extramodules\n" pushd /etc/httpd >/dev/null ln -sf ../../usr/$LIB/apache-extramodules extramodules popd >/dev/null fi if [ ! -e $CONF/httpd.conf -a -e $CONF/httpd.conf.rpmsave ];then gprintf "Recreating httpd.conf from backup file\n" rm -f $CONF/httpd.conf mv $CONF/httpd.conf.rpmsave $CONF/httpd.conf fi if [ ! -e $CONF/httpd.conf -a -e $COMPAT/httpd.conf ];then gprintf "Recreating httpd.conf from compat file\n" rm -f $CONF/httpd.conf cp $COMPAT/httpd.conf $CONF/httpd.conf fi HTTPD=httpd HTTPDCONF="-f $CONF/httpd.conf" APACHEXMODS=`extramoduleargs /usr/$LIB/apache-extramodules` APACHEREGMODS=`moduleargs /usr/$LIB/apache` fi #If both servers are installed, perl runs as a proxy #and has no extra modules if [ -x $SBIN/$HTTPD -a -x $SBIN/$HTTPDPERL ]; then DEFINE="-DPERLPROXIED" PERLXMODS="" MSGPERL="$MSGPERL (running in proxied mode)" fi ### } ## Hack for ApacheJServ that takes forever to shut down and restart snooze() { for count in 1 2 3 4 5 6 7 8 9 ; do gprintf "."; sleep 1; done echo } conftest() { badconf=0 if [ -x $SBIN/$HTTPD ]; then action "Checking configuration sanity for %s: " "$MSG" \ $SBIN/$HTTPD -t \ $HTTPDCONF $DEFINE $APACHEXMODS $APACHEREGMODS badconf=$? fi if [ -x $SBIN/$HTTPDPERL ]; then action "Checking configuration sanity for %s: " "$MSGPERL" \ $SBIN/$HTTPDPERL -t \ $PERLFILE $DEFINE $PERLXMODS $PERLREGMODS [ $badconf = 0 ] && badconf=$? fi return $badconf } start() { for tries in $times_start; do if [ -x $SBIN/$HTTPDPERL -a ! -e $HTTPDPERLPID ]; then if [ $tries -eq 1 ]; then gprintf "Starting $HTTPDPERL: ";fi daemon $HTTPDPERL $PERLFILE $DEFINE $PERLXMODS $PERLREGMODS echo for wait in $sleep_time;do if [ ! -e $HTTPDPERLPID ]; then sleep 1;fi done fi if [ -x $SBIN/$HTTPD -a ! -e $HTTPDPID ]; then if [ $tries -eq 1 ]; then gprintf "Starting $HTTPD: ";fi daemon $HTTPD $HTTPDCONF $DEFINE $APACHEXMODS $APACHEREGMODS echo for wait in $sleep_time ;do if [ ! -e $HTTPDPID ]; then sleep 1;fi done fi done touch /var/lock/subsys/httpd } stop() { if [ -e $HTTPDPERLPID ]; then gprintf "Shutting down $HTTPDPERL: " killproc httpd-perl echo rm -f $HTTPDPERLPID fi if [ -e $HTTPDPID ]; then gprintf "Shutting down $HTTPD: " killproc httpd echo if [ -e /usr/$LIB/apache-extramodules/mod_jserv.so ]; then snooze while [ -e $HTTPDPID ]; do echo Trying harder snooze killproc httpd done fi rm -f $HTTPDPID fi # SPLITPID=`ps ax | grep /usr/sbin/advxsplitlogfile | grep -v grep | awk '{ print $1}'` # if ! [ -z "$SPLITPID" ]; then # # kill advxsplitlogfile zombies # kill -9 $SPLITPID # fi rm -f /var/lock/subsys/httpd } # See how we were called. case "$1" in start) detect start ;; stop) detect stop ;; extendedstatus) detect $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } ' echo gprintf "#######################################" gprintf "#######################################\n" if [ -x $SBIN/$HTTPD -a -x $SBIN/$HTTPDPERL ]; then $LYNX $STATUSURLPERL | awk ' /process$/ { print; exit } { print } ' echo gprintf "#######################################" gprintf "#######################################\n" fi ;; status) detect echo if [ -e $HTTPDPERLPID ]; then gprintf "Apache-mod_perl is running.\n" gprintf "$HTTPDPERL: `pidof $HTTPDPERL`\n" echo fi if [ -e $HTTPDPID ]; then gprintf "Apache is running.\n" gprintf "$HTTPD: `pidof $HTTPD`\n" echo fi if [ ! -e $HTTPDPID -a ! -e $HTTPDPERLPID ]; then gprintf "Apache is *not* running.\n" echo fi gprintf "Use %s extendedstatus for more information.\n" "$0" echo ;; restart) detect stop detect start ;; update|condrestart) detect if [ -e $HTTPDPID -o -e $HTTPDPERLPID ]; then stop conftest || exit $? start fi ;; reload|graceful) # in doubt, check both possible library dirs if [ -e /usr/lib/apache-extramodules/mod_jserv.so -o \ -e /usr/lib64/apache-extramodules/mod_jserv.so ]; then detect stop detect start else detect if [ -e $HTTPDPERLPID ]; then gprintf "Reloading $HTTPDPERL: " killproc httpd-perl -USR1 echo fi if [ -e $HTTPDPID ]; then gprintf "Reloading $HTTPD: " killproc httpd -USR1 echo fi fi ;; closelogs) detect if [ -e $HTTPDPERLPID ]; then gprintf "Sending HUP to $HTTPDPERL: " killproc httpd-perl -HUP echo fi if [ -e $HTTPDPID ]; then gprintf "Sending HUP to $HTTPD: " killproc httpd -HUP echo fi ;; configtest) detect conftest exit $? ;; *) gprintf "Usage: %s {start|stop|restart|reload/graceful|closelogs|update|status|configtest}\n" "$0" exit 1 esac exit 0