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 vertrex
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
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 do not have write rights to the installation directory, use:
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.
To save a script: Hold CTRL
then press X
. Then Y
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 nano
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/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" userconfigdir=$loc"/server/"$1"/settings/" var=$loc"/server/$1"/var/" 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 --userconfigdir $userconfigdir --vardir $var # 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
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 /home/vertrex/armagetronad/scripts
directory.
When creating/editing the scripts, I have used nano
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/vertrex/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 .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 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 .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 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 .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
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.
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_parser.sh and start_race.sh and 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 cmd.txt
file in the scripts folder which is easy to access from.
cd /home/vertrex/armagetronad/scripts
Then create the following files accordingly in the same folder as cmd.txt
start_parser.sh:
#!/bin/bash loc="/home/vertrex/armagetronad" tron=$loc"/bin/armagetronad-dedicated" var=$loc"/servers/racing/var/" log=$var"console_log.txt" userconfigdir=$loc"/servers/racing/settings/" parser=$loc"/scripts/rotation.php" ladderlog=$var"ladderlog.txt" cmd=$loc"/scripts/cmd.txt" tail -f $ladderlog | $parser | tee -a $cmd
start_race.sh:
#!/bin/bash loc="/home/vertrex/armagetronad" tron=$loc"/bin/armagetronad-dedicated" var=$loc"/servers/racing/var/" log=$var"console_log.txt" userconfigdir=$loc"/servers/racing/settings/" parser=$loc"/servers/racing/scripts/rotation" ladderlog=$var"ladderlog.txt" cmd=$loc"/scripts/cmd.txt" $tron --userconfigdir $userconfigdir --vardir $var --input $cmd
Remember to make them executable:
chmod +x start_parser.sh chmod +x start_race.sh
Also remember to change my username, Vertrex, to your username.
Once that's done, you open start_parser.sh
and start_race.sh
in different terminal windows or this won't work.
./start_parser.sh ./start_race.sh
After running them in two different terminals, open another terminal and cd into your scripts folder:
cd /home/vertrex/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 start_parser.sh
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 start_parser.sh
outputs texts which will be written into the cmd.txt and from there the server will read the cmd.txt file for new text entires and feeds them into the server and this is done through the use of --input
.
For example: in the extra window you have opened previously, type:
echo center_message Hello World >> cmd.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.
Manage Servers
Issues With Servers
When the server starts, it will load with it's default settings instead of the settings that you have indicated it to have in the script. To make the server load those settings, type:
exit
Your server will reset automatically and load with the settings you have specified.
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: ctf, high_rubber, hr+S and racing
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 CTRL
then hold A
and finally Press D
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 CTRL
and press C
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/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
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
Install Protobuf
Firstly go into your user folder:
cd /home/vertrex
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
and
sudo apt-get upgrade
Do those codes every month to keep your system and packages updated but be careful about the usage of sudo apt-get upgrade
. It can crash your platform or make some programs non-operational.
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.