#!/bin/sh
#
# /bin/sh replacement for startup
#

# grab the port number
port=2852
if [ "$1" != "" ]; then port=$1; fi

# set up
cd ../area
if [ -f shutdown.txt ]; then mv shutdown.txt shutdown2.txt; fi
if [ -f current.txt ]; then mv current.txt current2.txt; fi

allow cores
ulimit -c unlimited
# stack limit
# ulimit -s 1500

# renice +5 -p $$
# loop indefinately
while :
do
  # find a logfile

  index=1000
  name=cotn4-00
  while :
  do
    logfile=../log/$index.log
    if [ ! -e $logfile ]; then break; fi
    let index=$index+1
  done

  # run the mud
    ../src/mcloud $port >&! $log_file

  # shutdown?


  if [ -e shutdown.txt ]; then
    echo "startup: shutting down" >>$logfile
    exit 1
  fi
  
  # sleep, so if we fail on boot we don't get massive looping
  sleep 2
done
