Difference between revisions of "Running Multiple Servers on a single Linux computer"
Superkikim (talk | contribs) |
(--prefix=/etc/ .. WTF?) |
||
Line 11: | Line 11: | ||
In the "configure" command, the prefix will be the application directory. I have choose to install it in /etc/arma. Make your own choice: | In the "configure" command, the prefix will be the application directory. I have choose to install it in /etc/arma. Make your own choice: | ||
− | ./configure --prefix=/ | + | ./configure --prefix=/opt/armagetronad/ --disable-glout --enable-automakedefaults --disable-sysinstall --disable-etc --disable-useradd --disable-initscripts |
Then, compile and install: | Then, compile and install: | ||
Line 24: | Line 24: | ||
=== The tree === | === The tree === | ||
− | CD to /etc/arma | + | CD to /etc/arma |
+ | cd /opt/armagetronad/ | ||
Create the following subdirectories: | Create the following subdirectories: | ||
Line 34: | Line 35: | ||
We have now to create our servers. To do so, go to the servers directory you have created earlier, and for each server, create a subfolder with a one-word name for the server, and two subfolders: var and settings. For exemple: | We have now to create our servers. To do so, go to the servers directory you have created earlier, and for each server, create a subfolder with a one-word name for the server, and two subfolders: var and settings. For exemple: | ||
− | cd / | + | cd /opt/armagetronad/servers |
To create a server called server1: | To create a server called server1: | ||
Line 61: | Line 62: | ||
Now you have to create the scripts to launch and log all your servers. To allow managing each server separately, we will use GNU Screen. GNU screen is a terminal window manager. If it is not install on your server, you can get it with the usual installation tool (yum install screen, apt get screen, etc...). Again... advanced.... We assume you know how to install applications on linux and therefore, we assume GNU screen has been installed | Now you have to create the scripts to launch and log all your servers. To allow managing each server separately, we will use GNU Screen. GNU screen is a terminal window manager. If it is not install on your server, you can get it with the usual installation tool (yum install screen, apt get screen, etc...). Again... advanced.... We assume you know how to install applications on linux and therefore, we assume GNU screen has been installed | ||
− | You have to create two scripts. The first one will run a server and start logging the window in which the server has started. The second one will execute the first one for each folder in the /etc/arma/servers folder. It will create a window for each of them. Therefore, if you don't want a server to run, you will have to temporarily move the server folder out from the / | + | You have to create two scripts. The first one will run a server and start logging the window in which the server has started. The second one will execute the first one for each folder in the /etc/arma/servers folder. It will create a window for each of them. Therefore, if you don't want a server to run, you will have to temporarily move the server folder out from the /opt/armagetronad/servers directory. |
− | Save the scripts in the / | + | Save the scripts in the /opt/armagetronad/scripts directory. I use nano which is an easy text editor. |
=== The server script === | === The server script === | ||
Line 69: | Line 70: | ||
The first script will be called in this example: srv | The first script will be called in this example: srv | ||
− | nano / | + | nano /opt/armagetronad/scripts/srv |
That creates a text file called srv in the scripts directory. Write the following lines in the file: | That creates a text file called srv in the scripts directory. Write the following lines in the file: | ||
Line 75: | Line 76: | ||
screen -S $1 -X logtstamp on # print timestamps in log file | screen -S $1 -X logtstamp on # print timestamps in log file | ||
− | screen -S $1 -X logfile / | + | screen -S $1 -X logfile /opt/armagetronad/$1_%d%m%Y-%c.log # create a logfile in the logs subfolder |
screen -S $1 -X log on # Turn on logging for the server window | 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 | 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 /etc/arma/bin directory. | # 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 /etc/arma/bin directory. | ||
− | / | + | /opt/armagetronad/armagetronad-dedicated --configdir /opt/armagetronad/servers/$1/settings --vardir /opt/armagetronad/servers/$1/var |
# Clear the display, and indicates that the server has crashed, and then, wait 5 seconds before to restart the server, allowing you to quit with CTRL-C | # Clear the display, and indicates that the server has crashed, and then, wait 5 seconds before to restart the server, allowing you to quit with CTRL-C | ||
Line 88: | Line 89: | ||
done # end the loop | done # end the loop | ||
− | To save the file, press CTRL-X and Y to confirm. You have now a file called srv in / | + | To save the file, press CTRL-X and Y to confirm. You have now a file called srv in /opt/armagetronad/scripts. |
=== the global script === | === the global script === | ||
− | Create the second script. I called it start: <code> nano / | + | Create the second script. I called it start: <code> nano /opt/armagetronad/scripts/start</code> |
#!/bin/bash | #!/bin/bash | ||
Line 100: | Line 101: | ||
if [ "$1" != "" ]; then | if [ "$1" != "" ]; then | ||
screen -S $1 -X quit # Kill the window if it exists already, avoiding to run the same server twice | screen -S $1 -X quit # Kill the window if it exists already, avoiding to run the same server twice | ||
− | screen -dmS $1 / | + | screen -dmS $1 /opt/armagetronad/scripts/srv $1 # start a GNU screen window with the specified server inside |
else | else | ||
− | for f in $(ls / | + | for f in $(ls /opt/armagetronad/servers/.) # start a loop running the following command for any existing folders in the /opt/armagetronad/servers folder |
do | do | ||
screen -S $f -X quit # Kill the window if it exists already, avoiding to run the same server twice | screen -S $f -X quit # Kill the window if it exists already, avoiding to run the same server twice | ||
− | screen -dmS $f / | + | screen -dmS $f /opt/armagetronad/scripts/srv $f # start a GNU screen window with the server inside for each server folder |
done # ends the loop | done # ends the loop | ||
fi | fi | ||
Line 112: | Line 113: | ||
=== Starting all servers === | === Starting all servers === | ||
− | To make your servers start at boot, edit the /etc/rc.local file and add the "start" script at the end <code>/ | + | To make your servers start at boot, edit the /etc/rc.local file and add the "start" script at the end of <code>/opt/armagetronad/scripts/start</code> |
If you want to manually start all servers, just run the <code>./start</code> script. | If you want to manually start all servers, just run the <code>./start</code> script. | ||
Line 118: | Line 119: | ||
=== Starting a single specific server === | === Starting a single specific server === | ||
− | If you want to start (or restart) a single server, just run | + | If you want to start (or restart) a single server, just run |
+ | ./start servername | ||
== Server management == | == Server management == | ||
Line 145: | Line 147: | ||
=== Log files === | === Log files === | ||
− | Everytime the <code>srv</code> script is run, a new logfile will be created in the / | + | Everytime the <code>srv</code> script is run, a new logfile will be created in the /opt/armagetronad/logs folder. Keep an eye on log sizes. You don't want to run out of disk space because of Armagetron Advanced, do you ? |
=== Test the server autorestart === | === Test the server autorestart === |
Revision as of 12:46, 3 January 2009
Introduction
If you like to experiment new settings, it might be that you come with a set of interesting servers. A shame if you cannot run them all at the same time. Here is how you can achieve this on a Linux server. Please refer to the lag and bandwidth chapters in the wiki before to run multiple servers. If you run too many, you might end with a very bad gameplay.
This chapter will present you an easy way to run multiple servers on a single Linux computer, using GNU screen.
Server installation
First of all, you have to install the Armagetron Advanced Dedicated Server from source, not using the provided install script. This will allow to manage at will the settings and var directories. To do so, download the latest source package, and untar it in a temporary folder. CD to that folder and run the following commands:
In the "configure" command, the prefix will be the application directory. I have choose to install it in /etc/arma. Make your own choice:
./configure --prefix=/opt/armagetronad/ --disable-glout --enable-automakedefaults --disable-sysinstall --disable-etc --disable-useradd --disable-initscripts
Then, compile and install:
make make install
Now, armagetron advanced dedicated is installed in the /etc/arma folder.
Preparing the servers
The tree
CD to /etc/arma
cd /opt/armagetronad/
Create the following subdirectories:
mkdir servers 'This folder will be used to store server configurations mkdir logs 'This one will be used to save the server logs mkdir scripts 'And this one will be used to same the scripts we will see below
We have now to create our servers. To do so, go to the servers directory you have created earlier, and for each server, create a subfolder with a one-word name for the server, and two subfolders: var and settings. For exemple:
cd /opt/armagetronad/servers
To create a server called server1:
mkdir server1 mkdir server1/settings mkdir server1/var
then copy your config files in the settings subfolder.
You can then create a second server, and more...
mkdir server2 mkdir server2/settings mkdir server2/var
and so on...
The setting files
For each server, do not forget to create a "server_info.cfg" file (search the wiki about it), and to change the port number. Port can be from 4534 to 4540, meaning you can safely run up to 7 servers on the same computer, depending obviously on the settings of each servers, and the bandwidth they need.
We assume that you know enough about Server Administration to understand the above explainations. This article is about Advanced Server Administration, isn't it ?
The scripts
Now you have to create the scripts to launch and log all your servers. To allow managing each server separately, we will use GNU Screen. GNU screen is a terminal window manager. If it is not install on your server, you can get it with the usual installation tool (yum install screen, apt get screen, etc...). Again... advanced.... We assume you know how to install applications on linux and therefore, we assume GNU screen has been installed
You have to create two scripts. The first one will run a server and start logging the window in which the server has started. The second one will execute the first one for each folder in the /etc/arma/servers folder. It will create a window for each of them. Therefore, if you don't want a server to run, you will have to temporarily move the server folder out from the /opt/armagetronad/servers directory.
Save the scripts in the /opt/armagetronad/scripts directory. I use nano which is an easy text editor.
The server script
The first script will be called in this example: srv
nano /opt/armagetronad/scripts/srv
That creates a text file called srv in the scripts directory. Write the following lines in the file:
#!/bin/bash screen -S $1 -X logtstamp on # print timestamps in log file screen -S $1 -X logfile /opt/armagetronad/$1_%d%m%Y-%c.log # create a logfile in the logs subfolder 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 /etc/arma/bin directory. /opt/armagetronad/armagetronad-dedicated --configdir /opt/armagetronad/servers/$1/settings --vardir /opt/armagetronad/servers/$1/var # Clear the display, and indicates that the server has crashed, and then, wait 5 seconds before to restart the server, allowing you to quit with CTRL-C clear 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 /opt/armagetronad/scripts.
the global script
Create the second script. I called it start: nano /opt/armagetronad/scripts/start
#!/bin/bash # If you run the script with a parameter (server name), only that server will be start. Otherwise, all servers in the /etc/arma/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 /opt/armagetronad/scripts/srv $1 # start a GNU screen window with the specified server inside else for f in $(ls /opt/armagetronad/servers/.) # start a loop running the following command for any existing folders in the /opt/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 /opt/armagetronad/scripts/srv $f # start a GNU screen window with the server inside for each server folder done # ends the loop fi
Save it and exit the same way as before.
Starting all servers
To make your servers start at boot, edit the /etc/rc.local file and add the "start" script at the end of /opt/armagetronad/scripts/start
If you want to manually start all servers, just run the ./start
script.
Starting a single specific server
If you want to start (or restart) a single server, just run
./start servername
Server management
GNU screen
GNU screen is a great tool. As explained above, it allow a multi-windowed environement on the simple terminal. And even better, the windows stay alive, evening when you disconnect from the server. You can find everything about GNU screen by typing man screen
on a terminal.
Listing the running servers
To see the existing windows, meaning here, the running servers, type screen -ls
. It will gives you a list of running windows.
Accessing and leaving a server console
To attach to a window, type screen -r servername
. You will be in the server console. You can then do all the command you would usually do there. Remote moderation, server adjustment, and so on.
To detach, but keep the server running, press CTRL-a d (control key + low case A, then low case D to detach). You can find all GNU screen key combinations by reading man screen
.
Killing a server
To kill a server, attach to its window, and press CTRL-C. This will kill the script, and the window. Then press ESC to exit the dead window. An alternate way is to run
screen -S servername -X quit
This will kill and end the window and the server inside.
Log files
Everytime the srv
script is run, a new logfile will be created in the /opt/armagetronad/logs folder. Keep an eye on log sizes. You don't want to run out of disk space because of Armagetron Advanced, do you ?
Test the server autorestart
If you want to try if the server restarts when it crash, do not press CTRL-C into the window. CTRL-C kill the script, therefore it will not be able to restart. Instead, run the quit
command inside the server console. It will close the server, and you will be able to see the message, and the server restarting.
Credits
This article has been written by Superkikim. These scripts and setup details are used to run the "FAST TRACK" servers.