#! /bin/csh -f
# Set the port number.
set port = 7000
set basedir = /var/www/vhosts/haslage.net/private/rm6
set email = "admin@localhost"
if ( "$1" != "" ) set port="$1"
if ( "$2" == "newlog" ) rm $basedir/log/*
# Change to area directory.
cd $basedir/area
# Set limits.
nohup
nice
if ( -e shutdown.txt ) rm -f shutdown.txt
unlimit core
unlimit stack
while ( 1 )
# If you want to have logs in a different directory,
# change the 'set logfile' line to reflect the directory name.
set index = 1000
while ( 1 )
set logfile = $basedir/log/$index.log
if ( ! -e $logfile ) break
@ index++
# Keep the log files from taking up all the space.
if ( $index > 1025 ) then
rm ../log/*.log
set index = 1000
endif
end
# Record starting time
date > $logfile
# Run SMAUG.
# Check if already running
set matches = `netstat -an | grep ":$port " | grep -c LISTEN`
if ( $matches >= 1 ) then
# Already running
echo Port $port is already in use.
exit 0
endif
$basedir/src/rmexe $port >>&! $logfile
if ( -e core ) then
\mv core ../src
cd ../src
date > $basedir/crash/$index.crash
gdb -batch -x commands rmexe core >> $basedir/crash/$index.crash
#rm -f core
cd $basedir/area
endif
# Restart, giving old connections a chance to die.
if ( -e $basedir/area/shutdown.txt ) then
echo "Script killed!" > $basedir/area/bootlog
cat $basedir/area/shutdown.txt > $basedir/area/bootlog
/usr/lib/sendmail $email < $basedir/area/bootlog
rm -f $basedir/area/bootlog
cp $basedir/area/shutdown.txt $basedir/area/shutdown.last
rm -f $basedir/area/shutdown.txt
exit 0
endif
sleep 5
end