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 find 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  so don't get confused. Change my username to YOUR username so everything will work the way it should. DO NOT HAVE SPACES IN YOUR USERNAME!!!

Requirements
To continue with the next steps you will have installed the following: 1) Have bzr installed 2) Have Z-Thread installed 3) Have "nano" (or your favorite text editor) Installed 4) Have "screen" installed 5) Have libxml2 installed 6) Have build-essentials

You can get the essentials from this link: Ubuntu_Installation

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/

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//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 apt-get install bzr build-essential automake libboost-dev libxml2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev ftgl-dev libglew-dev bison pkg-config autoconf autotools-dev libprotobuf-dev

Before taking the final steps, you need to create the folder to which your server will be installed in. mkdir /home//armagetronad

Now configure the server. ./configure --disable-glout --enable-authentication --prefix=/home//armagetronad --exec_prefix=/home//armagetronad --with-zthread

Installing Source Files
Once configuration is done, follow the next steps at installing the server make make install

If you do not have write rights to the installation directory, use: sudo make install

Now, our servers have been installed in the directory:

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//armagetronad

Create the sub directories as indicated below: mkdir servers     'This folder will be used to store your server configurations 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//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 		'this is the server that will be hosted mkdir /var		'this folder where the server's ladderlog, score, players will be stored mkdir /settings	'this is the folder where you place your config files such as settings_custom.cfg, settings.cfg, etc... mkdir /resource    'this is where your map files will be stored depending on your specified server mkdir /logs        'This one will be used to save the server logs

then copy your config files into the settings folder and the files that belong in the var folder.

You can create more servers like... mkdir racing mkdir racing/var mkdir racing/settings mkdir racing/resource mkdir racing/logs and many more.

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  directory.

To save a script: Hold  then press. Then  to save the script.

Check this website to understand more about the scripts ... Running_Multiple_Servers_on_a_single_Linux_computer#The_scripts

When creating/editing the scripts, I have used ''' because it was easier for me but you don't have to use the same method. You have the freedom to choose which ever editor you wish to use to create or edit any of these files/scripts.'''

Firstly go into the scripts folder to follow the steps below: cd /home//scripts

The Server Script
The first script will be called in this example: srv.sh nano srv.sh

That creates a  file called   in the scripts directory. Write the following lines in the file loc="/home//armagetronad" tron=$loc"/bin/armagetronad-dedicated" vardir=$loc"/servers/"$1"/var" userconfigdir=$loc"/servers/"$1"/settings" resourcedir=$loc"/servers/"$1"/resource/" mkdir $loc"/servers/"$1"/logs" screen -S $1 -X logtstamp on 					# print timestamps in log file screen -S $1 -X logfile $loc"/servers/"$1"/logs/"$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 $tron --vardir $vardir $tron --resourcedir $resourcedir --userconfigdir $userconfigdir --vardir $vardir echo "Server has crashed. It will restart immediately..., press CTRL-C to cancel" sleep 5 done # end the loop
 * 1) !/bin/bash
 * 1) 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
 * 2) in /home/vertrex/armagetronad/bin directory.
 * 1) 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

To save the file, press CTRL-X and Y to confirm. You have now a file called srv in /home//armagetronad/scripts

The Global Script
Create the second script. I called it start: nano start.sh

That creates a  file called   in the scripts directory. Write the following lines in the file loc="/home//armagetronad" 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 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
 * 1) !/bin/bash
 * 1) If you run the script with a parameter (server name), only that server will be start. Otherwise, all servers in
 * 2) the /home/<your_username>/armagetrnad/servers directory will be started
 * 1) /home/<your_username>/armagetronad/servers folder

Before you can run the script, you must make them executable: chmod +x srv.sh chmod +x start.sh

Advanced Scripts
In this part there are a few things that might interest you, such as the rotation script, one that is used to choose maps randomly per round.

For the sake of this part, I will be demonstrating to you how I used the rotation script to manage my racing server.

As always, all script are to be stored in the  directory.

When creating/editing the scripts, I have used ''' because it was easier for me but you don't have to use the same method. You have the freedom to choose which ever editor you wish to use to create or edit any of these files/scripts.'''

So go into the scripts folder to follow the steps shown below: cd /home/<your_username>/scripts

The Rotation Script
I found the script in a post that was made in the Armagetron Forums. I wanted to experiment with my racing maps in the 0.2.8-sty+ct version.

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  file with the name   in the scripts folder. <?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"; } } ?>
 * 1) !/usr/bin/php

To understand the components of the script, go to the post where it was originally made: Armagetron Forums: Map Rotation without 0.3

Remember to enable Ladderlog command in your server so that the script will rotate the maps: LADDERLOG_WRITE_ROUND_COMMENCING 1

The Server Script
OK, The following script is only for the racing server. However, you can change it for your own uses.

Create the server script. I called it race_srv: nano race_srv.sh

This creates a  file with the name   in the scripts folder. loc="/home/<your_username>/armagetronad" tron=$loc"/bin/armagetronad-dedicated" vardir=$loc"/servers/"$1"/var/" log=$var"console_log.txt" userconfigdir=$loc"/servers/"$1"/settings/" resourcedir=$loc"/servers/"$1"/resource" parser=$loc"/scripts/rotation.php" ladderlog=$var"ladderlog.txt" cmd=$loc"/scripts/cmd.txt" mkdir $loc"/servers/"$1"/logs" screen -S $1 -X logtstamp on                                   # print timestamps in log file screen -S $1 -X logfile $loc"/servers/"$1"/logs/"$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 tail -f $ladderlog | $parser | $tron --resourcedir $resourcedir --userconfigdir $userconfigdir --vardir $vardir | tee -a $log echo "Server has crashed. It will restart immediately..., press CTRL-C to cancel" sleep 5 done # end the loop
 * 1) !/bin/bash
 * 1) 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
 * 2) in /home/vertrex/armagetronad/bin directory.
 * 1) $tron --help
 * 1) 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

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  and  , 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 is only to start the racing server, race_srv.sh, but you can change it accordingly for your own purposes.

Create the server script. I called it race_start: nano race_start.sh

This creates a  file with the name   in the scripts folder. loc="/home/<your_username>/armagetronad" 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 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
 * 1) !/bin/bash
 * 1) If you run the script with a parameter (server name), only that server will be start. Otherwise, all servers in the /home/<your_username>/armagetrnad-0.2.8/servers director$
 * 2) will be started
 * 1) /home/<your_username>/armagetronad/servers folder

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/<your_username>/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. As that script is for the racing server, we type in  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.

Start Racing Server in Separate Sessions
As you can read from the title, this will section will explain how you can run your racing server with parser and not have to go into the server in the game to change the settings. That way is manually but this way is much quicker and easier.

To do this, you will need three files: start_race_parser.sh start_race_server.sh cmd_race.txt These can be named with any names but in my case as I'm talking about racing, I will relate them to the racing.

Create the  file in the scripts folder which is easy to access from. cd /home/<your_username>/armagetronad/scripts Then create the following files accordingly in the same folder as cmd_race.txt

start_race_parser.sh: loc="/home/<your_username>/armagetronad" tron=$loc"/bin/armagetronad-dedicated" var=$loc"/servers/racing/var/" log=$var"console_log.txt" userconfigdir=$loc"/servers/racing/settings/" parser=$loc"/scripts/race_rotation.php" ladderlog=$var"ladderlog.txt" cmd=$loc"/scripts/cmd_race.txt" tail -f $ladderlog | $parser | tee -a $cmd
 * 1) !/bin/bash

start_race_server.sh: loc="/home/<your_username>/armagetronad" tron=$loc"/bin/armagetronad-dedicated" vardir=$loc"/servers/racing/var/" log=$var"console_log.txt" userconfigdir=$loc"/servers/racing/settings/" resourcedir=$loc"/servers/racing/resource/" parser=$loc"/scripts/rotation.php" ladderlog=$var"ladderlog.txt" cmd=$loc"/scripts/cmd.txt" $tron --input $cmd --resourcedir $resourcedir --userconfigdir $userconfigdir --vardir $vardir
 * 1) !/bin/bash

Remember to make them executable: chmod +x start_race_parser.sh chmod +x start_race_server.sh

Also remember to change my username, <your_username>, to your username.

Once that's done, you open  and   in different terminal windows or this won't work. ./start_race_parser.sh ./start_race_server.sh After running them in two different terminals, open another terminal and cd into your scripts folder: cd /home/<your_username>/armagetronad/scripts

Once in the folder, start your game and start playing and when you look at the terminals, you will see that the terminal window which you used to open  starts to output texts and from those texts, your server changes maps accordingly (depends on how you arranged your maps that is). How does that work?

I'm not an expert when it comes to scripts but I'll explain the best I can which I gathered form the people that have explained it to me. The  outputs texts which will be written into the cmd.txt and from there the server will read the cmd_race.txt file for new text entires and feeds them into the server and this is done through the use of.

For example: in the extra window you have opened previously, type: echo center_message Hello World >> cmd_race.txt

This should automatically pop-up a message in your game with big writings in the center saying "Hello World".

From that little example you should now know how it's done, how you can change settings in the server without actually being in the server.

Multiple Servers
Managing the servers should be pretty easy once you get to understand what you need to do.

Let's have an example that you started 4 servers:

How are you going to keep a watch on them from within a single terminal ... 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. Firstly let's call the current terminal, T1 ... make things easier to understand.

Stepped Process: Step 1: Go to File. Step 2: Select"Open Terminal"

A new terminal window should show up, let's call it T2. With T2, you can monitor another server. Repeat the "Stepped Process" and you can monitor many more servers.

In each terminal window, type one of each of the servers that are running: 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.

The GNU Screen
You don't really need to know a 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.

Show Current Running Servers
To see the servers that are running, try this: screen -ls

It will display the servers that are currently running in your system.

Access/Leave Specific Server
To access a certain server, enter: screen -r [Server Name]

To detach from the server, do: Hold  then hold   and finally Press

When you detach from the server window, it doesn't mean the server will shutdown. You simply are leaving the server window to get back to the normal window which you have started from. To re-enter the server window, 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  and press

That should automatically bring you back to your terminal window and a message should appear saying: [screen is terminating]

Extras
These are snippets of stuff that I found useful when I had problems with things when running my server.

Install Z-Thread
Firstly go into your user folder: cd /home/<your_username>

Downloading ZThread Compressed File wget http://vertrex.tk/sources/ZThread/ZThread-2.3.2.tar

Extracting File tar -xvf ZThread-2.3.2.tar

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 ERROR COMES BACK AS cannot create regular file '/usr/lib/libZThread-2.3.so.2.0.0': Permission Denied That only means that you do not have ROOT privileges. This is the most common case for any regular user who has ubuntu and windows installed. To get around this, you simply do sudo su which should put you in root. Mind that it might not work but for me, it did! Once it works, do the same process as above and it will complete!

Install Libtools
You simply enter the following into the terminal and it will automatically should install it for you: sudo apt-get install libtool

Install Protobuf
Firstly go into your user folder: cd /home/<your_username>

Downloading the compressed File wget http://protobuf.googlecode.com/files/protobuf-2.0.3.tar.bz2

Extracting File tar -jxvf ./protobuf-2.0.3.tar.bz2

Entering into the extracted folder cd protobuf-2.0.3

Configuring the source files ./configure --prefix=/usr

Perform the installation of the source files sudo make install

Install Screen
This will automatically install the screen command which you need for these scripts sudo apt-get install screen

Install PHP
This will automatically install the screen command which you need for these scripts sudo apt-get install php5

Install BZR
This will automatically start the installation of the bzr which you will need in order to download the armagetronad source files. sudo apt-get install bzr

Install libxml2
This will automatically start to install libxml2. This is needed if the ./configure is to work properly. sudo apt-get install libxml2-dev

Update Packages
This should be done first as most virtual servers won't be usable before being updated. sudo apt-get update

Credits
This tutorial was written by vertrex a.k.a LOVER$BOY. Some of the scripts were written by Superkikim in his tutorial which I modified a little for the uses of my servers. I originally thought of editing and adding the the data that I've shown you here into his tutorial ... but his tutorial was the one that had helped me to get this far. So I instead chose to make something similar to his but with the additional data.

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.