#!/bin/sh
# -*- Bash -*-
# Start the local Meta-HTML Web Servers running.
#
dir=`echo $0 | sed -e 's@/[^/]*$@@'`
if [ "$dir" = "" ]; then dir=`pwd`; fi
PATH=$dir:$PATH
export PATH
export LD_LIBRARY_PATH
LD_LIBRARY_PATH="`echo $dir | sed -e 's@/[^/]*$@@'`/lib:/lib:/usr/lib:$LD_LIBRARY_PATH"

# List of hostnames that should start their own copy of Mhttpd.
HOSTNAMES=$1
if [ "$HOSTNAMES" = "" ]; then HOSTNAMES=$dir/LOCAL-SITES; fi
MHTTPD_HOSTS=`cat $HOSTNAMES`

if [ "$MHTTPD_HOSTS" ]; then
   # Start the mhttpd servers.
   for site in $MHTTPD_HOSTS; do
      confdir=/www/$site/conf
      if [ -r $confdir/mhttpd.conf ]; then
	 echo "Starting server for $site."
	 (mhttpd --config $confdir/mhttpd.conf)
	 sleep 1
      elif [ -x /www/$site/start-server ]; then
	 echo -n "Starting server for $site..."
	 (cd /www/$site; ./start-server)
	 echo "done."
      else
	 echo "Cannot start server for $site: No file $confdir/mhttpd.conf."
      fi
   done
fi

