Sophie

Sophie

distrib > Mandriva > 2006.0 > i586 > media > main-src > by-pkgid > 616effbc956a8423e85dc4981bf996f4 > files > 8

httpd2-naat-0.8-10mdk.src.rpm

#!/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: httpd2-naat
# pidfile: /var/run/httpd2-naat.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=httpd2-naat
HTTPDPID=/var/run/httpd2-naat.pid
HTTPDPERL=httpd2-naat-perl
HTTPDPERLPID=/var/run/httpd2-naat-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=$httpd2-naat 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_httpd2-naat 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-naat-perl ]; then
   detectlib $SBIN/httpd2-naat-perl
   MSGPERL="Apache 2.0/mod_perl"
   HTTPDPERL=httpd2-naat-perl
   PERLFILE="-f $CONF/httpd2-naat-perl.conf"
   PERLXMODS="-DAPACHE2 `extramoduleargs /usr/$LIB/apache2-extramodules`"
   PERLREGMODS=`moduleargs /usr/$LIB/apache2`
elif [ -x $SBIN/httpd2-naat-perl ]; then
   detectlib $SBIN/httpd2-naat-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/apache2 modules
     popd >/dev/null
   fi
   if [ ! -e /etc/httpd/extramodules ];then
     gprintf "Re-creating /etc/httpd/extramodules\n"
     pushd /etc/httpd2-naat >/dev/null
     ln -sf ../../usr/$LIB/apache2-extramodules extramodules
     popd >/dev/null
   fi
   if [ ! -e $CONF/httpd2-naat-perl.conf -a -e $CONF/httpd2-naat-perl.conf.rpmsave ];then
    gprintf "Recreating httpd2-naat-perl.conf from backup file\n"
    mv $CONF/httpd2-naat-perl.conf.rpmsave $CONF/httpd2-naat-perl.conf
   fi
   if [ ! -e  $CONF/httpd2-naat-perl.conf -a -e $COMPAT/httpd2-naat-perl.conf ];then
    gprintf "Recreating httpd2-naat-perl.conf from compat file\n"
    rm -f $CONF/httpd2-naat-perl.conf
    cp $COMPAT/httpd2-naat-perl.conf $CONF/httpd2-naat-perl.conf
   fi
   HTTPDPERL=httpd2-naat-perl
   PERLFILE="-f $CONF/httpd2-naat-perl.conf"
   PERLXMODS=`extramoduleargs /usr/$LIB/apache2-extramodules`
   PERLREGMODS=`moduleargs /usr/$LIB/apache2`
fi

if [ ! -x $SBIN/httpd2-naat -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-naat -a ! -e $CONF/RUN1.3 ]; then
   detectlib $SBIN/httpd2
   MSG="Apache 2.0"
   HTTPD=httpd2-naat
   HTTPDCONF="-f $CONF/httpd2-naat.conf"
   APACHEXMODS="-DAPACHE2 `extramoduleargs /etc/httpd/2.0/extramodules`"
   APACHEREGMODS=`moduleargs /etc/httpd/2.0/modules`
elif [ -x $SBIN/httpd2-naat ]; then
   detectlib $SBIN/httpd2-naat
   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/apache2 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/apache2-extramodules extramodules
     popd >/dev/null
   fi
   if [ ! -e  $CONF/httpd2-naat.conf -a -e $CONF/httpd2-naat.conf.rpmsave ];then
    gprintf "Recreating httpd2-naat.conf from backup file\n"
    rm -f $CONF/httpd2-naat.conf
    mv $CONF/httpd2-naat.conf.rpmsave $CONF/httpd2-naat.conf
   fi
   if [ ! -e  $CONF/httpd2-naat.conf -a -e $COMPAT/httpd2-naat.conf ];then
    gprintf "Recreating httpd2-naat.conf from compat file\n"
    rm -f $CONF/httpd2-naat.conf
    cp $COMPAT/httpd2-naat.conf $CONF/httpd2-naat.conf
   fi
   HTTPD=httpd2-naat
   HTTPDCONF="-f $CONF/httpd2-naat.conf"
   APACHEXMODS=`extramoduleargs /usr/$LIB/apache2-extramodules`
   APACHEREGMODS=`moduleargs /usr/$LIB/apache2`
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/httpd2-naat
}

stop() {
	if [ -e $HTTPDPERLPID ]; then 
		gprintf "Shutting down $HTTPDPERL: "
		killproc httpd2-naat-perl
		echo
		rm -f $HTTPDPERLPID
	fi
	if [ -e $HTTPDPID ]; then 
		gprintf "Shutting down $HTTPD: "
		killproc httpd2-naat
		echo
		if [ -e /usr/$LIB/apache-extramodules/mod_jserv.so ]; then
			snooze
			while [ -e $HTTPDPID ]; do
				echo Trying harder
				snooze
				killproc httpd2-naat
			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/httpd2-naat
}

# 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 httpd2-naat-perl -USR1
			echo
		fi
		if [ -e $HTTPDPID ]; then 
			gprintf "Reloading $HTTPD: "
			killproc httpd2-naat -USR1
			echo
		fi
	fi
	;;
  closelogs)
        detect
	if [ -e $HTTPDPERLPID ]; then 
		gprintf "Sending HUP to $HTTPDPERL: "
		killproc httpd2-naat-perl -HUP
		echo
	fi
	if [ -e $HTTPDPID ]; then 
		gprintf "Sending HUP to $HTTPD: "
		killproc httpd2-naat -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