Ptserver script

From Peragro Tempus Wiki

Jump to: navigation, search
#!/bin/bash
#===============================================================================
#
#          FILE:  ptserver.sh
# 
#         USAGE:  Launch from commandline or icon
# 
#   DESCRIPTION:  Wrapper script for starting and stopping your Peragro Tempus Server. 
# 
#       OPTIONS:  none
#  REQUIREMENTS:  none
#          BUGS:  server running detection might report incorrectly
#         NOTES:  None atm
#        AUTHOR:  Brant Watson 
#       COMPANY:  Vaalnor Inc.
#       VERSION:  1.0
#       CREATED:  04/08/2008
#      REVISION:  14
#===============================================================================

# Setup a variable in advance to prevent an error on killing of processes, just in case. Bad Hack I know!
PT_PID=1

function choose {
       # Displays dialog prompting user to either start or stop server.
       RET=`zenity --list --radiolist --width=350 --height=180 \
               --title "PT Server Launcher" \
               --column="" --column $"Disk" --column $"Description" \
               TRUE    $"1. Server"            $"Launches Server" \
	       FALSE   $"2. Stop Server"       $"Kill the PT Server"`     

       if echo "$RET" | grep $"1"; then

	server_launch
	
       fi

       if echo "$RET" | grep $"2"; then

	server_kill       

       fi
}

function server_launch

{

	ps aux | grep ./peragro-server

	if [ $? -eq 0 ] ; then
	zenity --info --title "PT Server Launcher" --text $"Server already running."
	else
	echo "Launching Server...."
	./peragro-server >> Log.txt & PT_PID=$!
	zenity --info --title "PT Server Launcher" --text $"Server has been launched!"
	echo "Server Launched!"
	fi


	choose

	echo "Server Launched!"
}

function server_kill
{

	echo "Killing Server..."
	kill $PT_PID
	zenity --info --title "PT Server Launcher" --text $"Server has been killed."
	echo "Server Killed"

	choose

}

function server_kill_on_exit
{

	echo "Killing Server..."
	kill $PT_PID
	zenity --info --title "PT Server Launcher" --text $"Server has been killed."
	echo "Server Killed..."

}

function quit_ptsl
{

	ps aux | grep ./server

	if [ $? -eq 0 ] ; then

	server_kill_on_exit

else

	echo "Server Not running so not exiting"

fi

}


# Meat of the wrapper. This launches the necessary functions.

choose

quit_ptsl

# Quit with the proper return value
exit 0
Personal tools