#!/bin/sh
# -*- Bash -*-
# Stop local Meta-HTML Web Servers from running.
#

# List of hostnames that should start their own copy of Mhttpd.
dir=`echo $0 | sed -e 's@/[^/]*$@@'`
if [ "$dir" = "" ]; then dir=`pwd`; fi
HOSTNAMES=$1
if [ "$HOSTNAMES" = "" ]; then HOSTNAMES=$dir/LOCAL-SITES; fi
MHTTPD_HOSTS=`cat $HOSTNAMES`

if [ "$MHTTPD_HOSTS" ]; then
   for server in $MHTTPD_HOSTS; do
      if [ -x /www/$server/stop-server ]; then
	 echo -n "Stopping $server..."
	 (cd /www/$server; ./stop-server)
	 echo  "done."
      fi
      if [ -f /www/$server/conf/mhttpd.pid ]; then
	 echo -n "Stopping $server..."
	 kill -TERM `cat /www/$server/conf/mhttpd.pid`;
	 rm -f /www/$server/conf/mhttpd.pid;
	 echo  "done."
      fi
      if [ -f /www/$server/conf/httpd.pid ]; then
	 echo -n "Stopping $server..."
	 kill -TERM `cat /www/$server/conf/httpd.pid`;
	 rm -f /www/$server/conf/httpd.pid;
	 echo  "done."
      fi
      if [ -f /www/$server/mhttpd/conf/mhttpd.pid ]; then
	 echo -n "Stopping $server..."
	 kill -TERM `cat /www/$server/mhttpd/conf/mhttpd.pid`;
	 rm -f /www/$server/mhttpd/conf/mhttpd.pid;
	 echo  "done."
      fi
      if [ -f /www/$server/apache/conf/httpd.pid ]; then
	 echo -n "Stopping $server..."
	 kill -TERM `cat /www/$server/apache/conf/httpd.pid`;
	 rm -f /www/$server/apache/conf/httpd.pid;
	 echo  "done."
      fi
   done
fi
