#!/bin/sh
# Copyright (c) 2012 Terrax2
case "$1" in
start)
if [ -e tsdns.pid ]; then
if ( kill -0 $(cat tsdns.pid) 2> /dev/null ); then
echo "The server is already running, try restart or stop"
exit 1
else
echo "tsdns.pid found, but no server running. Possibly your previously started server crashed"
echo "Please view the logfile for details."
rm tsdns.pid
fi
fi
echo "Starting the TSDNS"
if [ -e tsdnsserver_linux_x86 ]; then
if [ ! -x tsdnsserver_linux_x86 ]; then
echo "tsdnsserver_linux_x86 is not executable, trying to set it"
chmod u+x tsdnsserver_linux_x86
fi
if [ -x tsdnsserver_linux_x86 ]; then
"./tsdnsserver_linux_x86" > /dev/null &
echo $! > tsdns.pid
echo "TSDNS server started, for details please view the log file"
else
echo "tsdnsserver_linux_x86 is not exectuable, cannot start TSDNS"
fi
else
echo "Could not find binary, aborting"
exit 5
fi
;;
stop)
if [ -e tsdns.pid ]; then
echo -n "Stopping the TSDNS server"
if ( kill -TERM $(cat tsdns.pid) 2> /dev/null ); then
c=1
while [ "$c" -le 300 ]; do
if ( kill -0 $(cat tsdns.pid) 2> /dev/null ); then
echo -n "."
sleep 1
else
break
fi
c=$((++c))
done
fi
if ( kill -0 $(cat tsdns.pid) 2> /dev/null ); then
echo "Server is not shutting down cleanly - killing"
kill -KILL $(cat tsdns.pid)
else
echo "\ndone"
fi
rm tsdns.pid
else
echo "No server running (tsdns.pid is missing)"
exit 7
fi
;;
restart)
$0 stop && $0 start || exit 1
;;
status)
if [ -e tsdns.pid ]; then
if ( kill -0 $(cat tsdns.pid) 2> /dev/null ); then
echo "Server is running"
else
echo "Server seems to have died"
fi
else
echo "No server running (tsdns.pid is missing)"
fi
;;
*)
echo "Usage: ${0} {start|stop|restart|status}"
exit 2
esac
exit 0