Running Multiple Servers In a Single Ubuntu Computer
Introduction
Hello everyone. This is a tutorial that I thought I should put together for those who are using Ubuntu and are struggling to grasp how to host more than one server. Before I go any further, I would like to say that this section does look similar to Running Multiple Servers on a single Linux computer ... but there is a difference. There are a couple of things that are different from the other and there are few others that have been added so people will fin them useful.
I do hope people will find this tutorial useful as I found the other one very useful but a bit confusing at times.
In the tutorial, My username is vertrex
so don't get confused. Change my username to YOUR username so everything will work the way it should.
Server Installation
Before you can think about setting up so that you can have multiple servers, firstly you need to have installed the Armagetron Advanced Dedicated Server in your computer. Now this is not specific as there are countless number of servers that the admins have either created or experiments or stable release.
The source codes for the servers can be found here: Armagetron Advanced: a Tron Clone in 3d
For the sake of this tutorial, our selection would be armagetron-sty+ct as that's a very popular selection to create servers with.
Downloading Source Files
The location where you should download your source code would be:
cd /home/vertrex
Now download the source files using the command: bzr branch
bzr branch lp:~armagetronad-ct/armagetronad/0.2.8-armagetronad-sty+ct
Configuring Source Files
Once the download completes, go into the source folder
cd /home/vertrex/0.2.8-armagetronad-sty+ct
Then run the bootstrap
./bootstrap.sh
if you get an error saying:
autom4te: cannot open autom4te.cache/requests: Permission denied aclocal: autom4te failed with exit status: 1 rm: remove write-protected regular file `aclocal.m4'? yes
then try:
sudo ./bootstrap.sh
Before taking the final steps, you need to create the folder to which your server will be installed in.
mkdir /home/vertrex/armagetronad
Now configure the server.
./configure --disable-glout --enable-authentication --prefix=/home/vertrex/armagetronad --exec_prefix=/home/vertrex/armagetronad --with-zthread
Installing Source Files
Once configuration is done, follow the next steps at installing the server
make make install
If you get an error that you were unable to install in the folder, then take the next step:
sudo make install
Now, our servers have been installed in the directory: /home/vertrex/armagetronad/
Server Preparations
Now, this is where you will have to do some thinking. You can make 7 servers as the ports list from 4534 to 4540. So, basically you have seven servers to make from. You could choose to make, Capture The Flag (S), High Rubber (S), Racing, etc...
To setup the multiple servers, please follow from next steps.
Server Directories
Go into your armagetronad installaiton folder
cd /home/vertrex/armagetronad
Create the sub directories as indicated below:
mkdir servers 'This folder will be used to store your server configurations mkdir logs 'This one will be used to save the server logs mkdir scripts 'And this one will be used to call scripts to start the servers or include with the servers
The next few steps are the fun parts. We will be making our servers. To do so, go into servers directory that you have just created.
cd /home/vertrex/armagetronad/servers
There, start creating sub folders for each of your servers. Example:
One server that I would like to create would be CTF which is capture the flag.
mkdir ctf 'this is the server that will be hosted mkdir ctf/var 'this folder where the server's ladderlog, score, players will be stored mkdir ctf/settings 'this is the folder where you place your config files such as settings_custom.cfg, settings.cfg, etc...
then copy your config files into the settings folder and the files that belong in the var folder.
You can create many more servers...
mkdir racing mkdir racing/var mkdir racing/settings
Simply put it that the server directories will be like this:
mkdir [Server Name] mkdir [Server Name]/var mkdir [Server Name]/settings
Normal Scripts
The scripts are used mainly to launch a specific server that is called using the script. The servers include Capture The Flag (S), High Rubber (S), Dogfight, Sumo
All the server scripts are to be stored in the /home/vertrex/armagetronad/scripts
directory.
Check this website to understand more about the scripts ... Running_Multiple_Servers_on_a_single_Linux_computer#The_scripts
Firstly go into the scripts folder to follow the steps below:
cd /home/vertrex/scripts
The Server Script
The first script will be called in this example: srv.sh
nano srv.sh
That creates a .sh
file called srv
in the scripts directory. Write the following lines in the file
#!/bin/bash loc="/home/vertrex/armagetronad" tron=$loc"/bin/armagetronad-dedicated" mkdir $loc/logs/$1 screen -S $1 -X logtstamp on # print timestamps in log file screen -S $1 -X logfile $loc/logs/$1/$1_%m-%d-%Y-%c.log # create a logfile in the logs subf screen -S $1 -X log on # Turn on logging for the server window while true; do # start a loop to allow server restart if it crashes #Runs the actual server. By default, the binary is called armagetronad-dedicated and is located in the prefix/bin directory. In this example, it is # in /home/vertrex/armagetronad/bin directory. $tron --vardir $loc/servers/$1/var $tron --userconfigdir $loc/servers/$1/settings # Shows the errors and indicates that the server has crashed, and then, waits 5 seconds before restarting the server, allowing you to quit with CTRL-C echo "Server has crashed. It will restart immediately..., press CTRL-C to cancel" sleep 5 done # end the loop
To save the file, press CTRL-X and Y to confirm. You have now a file called srv in /home/vertrex/armagetronad/scripts
The Global Script
Create the second script. I called it start:
nano start.sh
That creates a .sh
file called start
in the scripts directory. Write the following lines in the file
#!/bin/bash loc="/home/vertrex/armagetronad" # If you run the script with a parameter (server name), only that server will be start. Otherwise, all servers in # the /home/vertrex/armagetrnad/servers directory will be started if [ "$1" != "" ]; then screen -S $1 -X quit # Kill the window if it exists already, avoiding to run the same server twice screen -dmS $1 $loc/scripts/srv.sh $1 # start a GNU screen window with the specified server inside else for f in $(ls $loc/scripts/servers/.) # start a loop running the following command for any existing folders in the #/home/vertrex/armagetronad/servers folder do screen -S $f -X quit # Kill the window if it exists already, avoiding to run the same server twice screen -dmS $f $loc/scripts/srv.sh $f # start a GNU screen window with the server inside for each server folder done # ends the loop fi
Remember to save it in the same way as before.
Before you can run the script, you must make them executable:
chmod +x srv.sh chmod +x start.sh
Advanced Scripts
In this section, I will show you a few things that might interest you such as the rotation script, script that allows you to make your maps to change randomly. This is better than using the experimental armagetronad-0.3 version.
For the sake of this section I will be demonstrating to you how I manage my my racing server.
I got the script from a friend who made it for public so I used it to make my racing server to have it's maps randomly change.
Like before, all script are to be stored in the /home/vertrex/armagetronad/scripts
folder.
So go into the scripts folder to follow the steps shown below:
cd /home/vertrex/scripts
The Rotation Script
All credit goes to Kyle for writing the script.
Create the rotation script. I called it race_rotation:
nano race_rotation.php
This creates a .php
file with the name race_rotation
in the scripts folder.
#!/usr/bin/php <?php $maps=array("/path/to/map1.xml","/path/to/map2.xml"); while (1) { $line = rtrim(fgets(STDIN, 1024)); if ( preg_match( "/^ROUND_COMMENCING/", $line ) ){ $keywords = preg_split("/ /", $line); $map=rand (0 , count($maps )-1); echo "MAP_FILE ".$maps[$map]."\n"; echo "WAIT_FOR_EXTERNAL_SCRIPT 0\n"; sleep(6); echo "WAIT_FOR_EXTERNAL_SCRIPT 1\n"; } } ?>
To understand the components of the script, go to the post where it was originally made: Armagetron Forums: Map Rotation without 0.3
The Server Script
OK, The following script only for racing server but you can alter it for your own servers if you wish to.
Create the server script. I called it race_srv:
nano race_srv.sh
This creates a .sh
file with the name race_srv
in the scripts folder.
#!/bin/bash loc="/home/vertrex/armagetronad" tron=$loc"/bin/armagetronad-dedicated" var=$loc"/servers/"$1"/var/" log=$var"console_log.txt" userconfigdir=$loc"/servers/"$1"/settings/" parser=$loc"/scripts/race_rotation.php" ladderlog=$var"ladderlog.txt" mkdir $loc/logs/$1 screen -S $1 -X logtstamp on # print timestamps in log file screen -S $1 -X logfile $loc/logs/$1/$1_%m-%d-%Y-%c.log # create a logfile in the logs subf screen -S $1 -X log on # Turn on logging for the server window while true; do # start a loop to allow server restart if it crashes #Runs the actual server. By default, the binary is called armagetronad-dedicated and is located in the prefix/bin directory. In this example, it is # in /home/vertrex/armagetronad/bin directory. tail -f $ladderlog | $parser | $tron --userconfigdir $userconfigdir --vardir $var| tee -a $log # Shows the errors and indicates that the server has crashed, and then, waits 5 seconds before restarting the server, allowing you to quit with CTRL-C echo "Server has crashed. It will restart immediately..., press CTRL-C to cancel" sleep 5 done # end the loop
To use your rotation script for other servers, change the rotation script name in the script to your rotation script's name:
parser=$loc"/scripts/[Script Name].php"
To know more commands other than userconfigdir
and vardir
, try this in the script which will give you a window with the other things you can have:
$tron --help
The Global Script
OK, The following script only to start the racing server but you can alter it for your own servers if you wish to.
Create the server script. I called it race_start:
nano race_start.sh
This creates a .sh
file with the name race_start
in the scripts folder.
#!/bin/bash loc="/home/vertrex/armagetronad" # If you run the script with a parameter (server name), only that server will be start. Otherwise, all servers in the /home/vertrex/armagetrnad-0.2.8/servers director$ # will be started if [ "$1" != "" ]; then screen -S $1 -X quit # Kill the window if it exists already, avoiding to run the same server twice screen -dmS $1 $loc/scripts/race_srv.sh $1 # start a GNU screen window with the specified server inside else for f in $(ls $loc/scripts/servers/.) # start a loop running the following command for any existing folders in the # /home/vertrex/armagetronad/servers folder do screen -S $f -X quit # Kill the window if it exists already, avoiding to run the same server twice screen -dmS $f $loc/scripts/race_srv.sh $f # start a GNU screen window with the server inside for each server folder done # ends the loop fi
Remember to save it in the same way as before.
Before you can run the script, you must make them executable:
chmod +x race_rotation.php chmod +x race_srv.sh chmod +x race_start.sh
Running Servers
Starting the servers shouldn't be that hard if you follow the steps given below:
Start All Servers
To start all the servers check this link to fin out just how to do it as I didn't find it very useful for my purposes: Running_Multiple_Servers_on_a_single_Linux_computer#Starting_all_servers.
Start Normal Servers
Firstly go into your scripts folder
cd /home/vertrex/armagetronad/scripts
Then simply run start.sh script using the following method
./start.sh [Server Name]
If you get a message saying:
No screen session found.
Don't panic that there is an error in the script. Try the next step:
screen -r [Server Name]
Start Racing Servers
In the scripts folder, run race_start.sh
. As that script is for the racing server, we type in racing
or something like that depending on the name you have given your racing folder.
./race_start.sh racing
Ok, the racing scripts are a little different to the normal scripts. It's not much difference. You follow the same steps as above and enter into the new screen that the server will start in but what's different is that you can't enter any commands in the server like you can with the normal ones.
Basically meaning, you have to manually enter settings rather than easily change settings without entering the server. That is to say, you enter into the server, login as Owner or Admin and change settings.
Manage Server
Managing the servers should be pretty easy once you get understand what to do after reading what I have to say below:
If you started like, for example 4 servers: ctf, high_rubber, hr+S, racing
How are you going to keep a watch on them from withing a single terminal? No. That's practically impossible. You can only watch over one server at a time but there is another way that you could use to watch over them ... open multiple terminal windows.
Go to the current terminal window that you used to open all the 4 servers, and click "Open Terminal". A new terminal window should open with the same position as you were in the current terminal which should be in the scripts directory. If you are not, then navigate yourself to the scripts folder
cd /home/vertrex/armagetronad/scripts
There type the other server name that you want to monitor. Just like that, continue opening terminals of 4 an then type in the server names that you want to monitor:
screen -r ctf screen -r high_rubber screen -r hr+s screen -r racing
Your computer screen would look full with all the terminal windows but don't worry. You can minimize them and continue doing whatever you wish to do while the servers are online.
You don't really need to great deal lot of information on how to manage servers in a GNU but if you wish to, then try:
man screen
It'll give you many commands that you can use in your terminal but be careful with them
When the server starts, it will load with it's default settings instead of the settings in your config files. To make the server load the settings, type:
exit
and your server will reset after 5 seconds with the settings from your config files as specified in the script.
List Current Running Servers
To see what servers that are running, try this:
screen -ls
It will display the number of servers that are currently running
Access/Leave Specific Server
To access a certain server, enter:
screen -r [Server Name]
To detach from the server, do:
Hold CTRL
then hold A
and finally Press D
When you detach from the server screen, it doesn't shutdown your server. You simply are leaving the server window to get back to the normal window that you started from. To re-enter the server, follow the steps given above on how to access the server.
Close A Server
To close a server, go into the server you want to close:
screen -r [Server Name]
Then Do: Hold CTRL
and press C
That should automatically bring you back to your terminal window and a message should appear saying:
Socket is Terminating
Credits
This tutorial was written by Vertrex a.k.a LOVER$BOY. Some of the scripts are written by Superkikim which I modified a little for the uses of my servers. I first thought of editing and adding these stuff but his is the original which helped me get this far so I chose to make something similar but with additional info.
I really do hope that people who read this will find it useful. In the title I may have called it only for Ubuntu Computers but it can be applied to any linux computer that exists today.
Extras
These are snippets of stuff that I found useful when I had problems with things when running my server.
Installing Z-Thread
Firstly go into your user folder:
cd /home/vertrex
Downloading ZThread Compressed File
wget http://voxel.dl.sourceforge.net/sourceforge/zthread/ZThread-2.3.2.tar.gz
Extracting File
tar -xzf ZThread-2.3.2.tar.gz
Entering into the extracted folder
cd ZThread-2.3.2
Configuring the source files
./configure CXXFLAGS="-fpermissive" --prefix=/usr/
Perform the installation of the source files
make make install
if the make install
didn't work, then try:
sudo make install
Install Libtools
You simply enter the following into the terminal and it will automatically should install it for you:
sudo apt-get install libtool