MG/Dedicated Server

< MG

275pages on
this wiki
Add New Page
Talk0 Share

Those informations are/may be very outdated, please go to: new wiki

Starting MegaGlest 3.6.0 it is possible to host a dedicated headless game server. This means you can now install MegaGlest on a dedicated or virtual private server hosted in a data center, or a virtual server on your computer. This can be quite useful since data centers usually provide way better network connectivity at affordable pricing than ISPs can provide (and users can afford) in residential areas, meaning less people will drop out of games, and there will be less latency ('better ping'). Moreover, dedicated servers can run 24/7 so servers can be available for hosting games at any time.

Requirements Edit

To host your own headless server, you will need a dedicated or virtual private server which roughly meets the minimum requirements the MegaGlest README lists. You should actually be okay with 512 MB unallocated RAM (remaing free memory after the system has fully started up), though. A multi-core system is strongly recommended, and if these are virtual cores (VPS) then this system should not be running any other services. Graphics or audio cards are not needed. You do need a low latency Internet connection, though. Bandwith is not usually a problem (it might be if you operate under strict bandwidth restrictions and your MegaGlest server offers mods for download).


Unless you own / rent a dedicated server where you can setup a VPS for MegaGlest, the cheapest way to host is probably to go with a Virtual Private Server (VPS). There are unbelievably many VPS providers out there and we have little to no experience with them so we can't really make a recommendation at this point. Prices range from less than US $10 per month to amounts which would be better spent on a dedicated server. Please check websites such as, and which compare and discuss various offers.

There are also few 'free' VPS offers. All we can say there is that Amazons free-for-one-year VPS and Host1Free's VPS do not provide sufficient resources to run a dedicated gameserver while some of the offers by may work based on the resources they list. But we haven't actually tried this, since, of course, this offer is not entirely free but you need to dance the hula-hula. Generally, there are only few free offers on the Internet now, and those are usually by idealistic computer enthusiasts, almost never by companies - those always come with strings attached (which is completely understandable from their profit driven perspective). There are also donation based offers, or organisations operating without the target of/need to make profits (community service / hosting / colocation providers), which can be a good choice.

Operating systemEdit

Since we have to decide for one operating system, we go the easy (and good) way and use Debian GNU/Linux 6.0 (Squeeze). These steps may also work on later Debian versions as well as on Ubuntu servers.

Install a minimal Debian GNU/Linux server. This can be done with a Debian Netinstall CD image as well as by many other ways. The details are considered out of the scope of this manual - see the Debian website and installation manual.

You should now have a working minimal Debian server. Start by working as the root user. Depending on how you will manage this server you may want to install some additional packages:

apt-get install unattended-upgrades openssh-server less screen

If you installed an SSH server you can do the remaining installation remotely.

MegaGlest installationEdit

The next steps are specific to the installation and configuration of MegaGlest on your dedicated server. If you already have a working multi-use(r) Debian 6.0 server, this is the point to start following this tutorial.

Still working as root, create a new restricted user megaglest:

adduser megaglest --disabled-password --gecos ""

Also as root, install dependencies for MegaGlest:

apt-get install xz-utils p7zip-full libsdl1.2debian libglu1 libsm6 libopenal1 libvorbisfile3 libglew1.5 libfontconfig1 libldap-2.4-2 libidn11 binutils

Now switch to the megaglest user, this is the last time you need to work as root:

su -l megaglest

Download binary and data archives for the latest stable MegaGlest release. If your server runs a 64 bit operating system (the arch command says x86_64) then go for the 64 bit Linux binary and data archives, otherwise use the 32 bit ones. You can download these using wget, here's an example on how to do it with MegaGlest 3.9.1 for a 64 bit server:


Unpack, add a convenient symlink, delete the GUI binaries you do not need on a server and create the configuration directory:

tar -xJf megaglest-data-3.9.1.tar.xz
ln -s megaglest-3.9.1 megaglest-server
cd megaglest-server
tar -xJf megaglest-binary-linux-x86_64-3.9.1.tar.xz
rm megaglest_g3dviewer start_megaglest_g3dviewer megaglest_editor start_megaglest_mapeditor
mkdir -p ~/.megaglest

Do a test run:

megaglest@gameserver:~/megaglest-server$ ./start_megaglest --version
gamedir [/home/megaglest/megaglest-server]
Looking for LDCONFIG []...
LDCONFIG environment variable is not set...
Found LDCONFIG using which [/sbin/ldconfig]...
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/x86_64-linux-gnu/]
default library [/home/megaglest/megaglest-server/lib/] is missing, attempting to find and link to a newer version if available...
new library link [/usr/lib/x86_64-linux-gnu/] pointed to from [/home/megaglest/megaglest-server/lib/]
default library [/home/megaglest/megaglest-server/lib/] is missing, attempting to find and link to a newer version if available...
new library link [/usr/lib/x86_64-linux-gnu/] pointed to from [/home/megaglest/megaglest-server/lib/]
default library [/home/megaglest/megaglest-server/lib/] is missing, attempting to find and link to a newer version if available...
new library link [/usr/lib/x86_64-linux-gnu/] pointed to from [/home/megaglest/megaglest-server/lib/]
default library [/home/megaglest/megaglest-server/lib/] is missing, attempting to find and link to a newer version if available...
new library link [/usr/lib/x86_64-linux-gnu/] pointed to from [/home/megaglest/megaglest-server/lib/]
default library [/home/megaglest/megaglest-server/lib/] is missing, attempting to find and link to a newer version if available...
new library link [/lib/x86_64-linux-gnu/] pointed to from [/home/megaglest/megaglest-server/lib/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/x86_64-linux-gnu/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/x86_64-linux-gnu/]
default library [/home/megaglest/megaglest-server/lib/] is missing, attempting to find and link to a newer version if available...
new library link [/usr/lib/x86_64-linux-gnu/] pointed to from [/home/megaglest/megaglest-server/lib/]
default library [/home/megaglest/megaglest-server/lib/] is missing, attempting to find and link to a newer version if available...
new library link [/usr/lib/x86_64-linux-gnu/] pointed to from [/home/megaglest/megaglest-server/lib/]
default library [/home/megaglest/megaglest-server/lib/] is missing, attempting to find and link to a newer version if available...
new library link [/usr/lib/x86_64-linux-gnu/] pointed to from [/home/megaglest/megaglest-server/lib/]
default library [/home/megaglest/megaglest-server/lib/] is missing, attempting to find and link to a newer version if available...
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/x86_64-linux-gnu/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/x86_64-linux-gnu/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/x86_64-linux-gnu/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/x86_64-linux-gnu/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/x86_64-linux-gnu/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/x86_64-linux-gnu/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/x86_64-linux-gnu/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/libx32/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/x86_64-linux-gnu/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/libx32/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/usr/lib/]
default library [/home/megaglest/megaglest-server/lib/] was found in [/lib/x86_64-linux-gnu/]
megaglest v3.9.1
Compiled using: GNUC: 40403 [64bit] on: Jan 18 2014 17:44:55 platform: Linux-X64 endianness: little
GIT: [Rev: 4628.11ac54a] - using STREFLOP [SSE] - [no-denormals]

These default library messages (which are sent to to the error output stream) are completely normal and can be ignored unless errors about missing libraries are reported. The only line returned to standard output are those three last lines which provide the version info. If MegaGlest fails to start here, please check the FAQ .

MegaGlest configurationEdit

You may now want to set a server name, this is currently done via the NetPlayerName option in glestuser.ini:

mkdir -p ~/.megaglest

echo 'NetPlayerName=MyTestServer' > ~/.megaglest/glestuser.ini

Obviously you should replace MyTestServer by something which nicely and uniquely describes this server (or its owner). Watch out, there is a low character limit in place.

You are now ready to go. However, for advanced configuration, many more options which may matter for a game server are available. Here is an optional example for a more complex ~/.megaglest/glestuser.ini file:

### For more information on these options, please consult

### Network settings

### Logging

### Audio
### Disable all sound processing

### File archives
#FileArchiveExtractCommandParameters=x -o{outputpath} {archivename}

These and all other glestuser.ini options are documented on this wiki. Note that they may change between releases, so when you upgrade your server to the latest version, be sure to read the changelog and review the INI document.

Firewall configurationEdit

Now you need to ensure that people can actually connect to your server from the Internet so that it will get listed on the master server. For this to work, Internet originated traffic must be able to reach the game server on several ports, and the game server needs to be able to connect to the masterserver, too.

Inbound connectivityEdit

  • TCP port 61357: game protocol port (PortServer option in glestuser.ini to change)
  • TCP ports 61358 to 61366: FTP ports (set the FTPServerPort option in glestuser.ini (defaults to 61358) to the low FTP port to change). FTP support is optional but recommended since it allows clients to download mods they are lacking from your server. The low FTP port is the FTP control port, the rest are FTP data ports.

If you are one of the few who do asymmetric port forwarding (the ports your MegaGlest game server binds to / listens on differ from the ports players need to connect to on your port forwarding device's WAN interface) then you can also set the ExternalPort option in glestuser.ini (which defaults to the value PortServer is set to).

Outbound connectivityEdit

In case you also regulate outbound traffic (most servers/networks do not), be sure that the following will be accessible from your MegaGlest server:

  •, TCP port 80
  •, TCP port 80

Note that the IP addresses these hostnames resolve to can change without notification (but they should do so rarely).


You should now be able to start a server and it should automatically publish to the master server (this can take up to two minutes).

To run a headless server and register with the masterserver run:

./start_megaglest --headless-server-mode=exit

(for full options run megaglest --help to see all parameters)

Currently available game servers are listed at Play.MG , so your server should show up there with its IP address and the server/player name you have set. If publishing to the master server does not seem to work try running the server with --verbose option as discussed in the FAQ

Once publishing succeeded, start MegaGlest on your desktop computer, connect to your new game server and play a test game, ideally with a another human network player who will help you test because there is a two network player minimum to start a game (contact us on hints how to work around this limit if needed). The first user connecting to a headless server controls it. If this user disconnects, the next user who connected already (or will connect) takes control.

A good test setup which stresses your server is an eight player game on the Eight Rivers map, with the Desert tileset, where all non-human slots are set to CPU Mega and every one of them is on a separate team. All human players can have their faction set to observer (set allow observers in advanced options first) so you don't actually have to play this game but can just watch.

Play this game for a while, pressing '?' (question mark) to activate debug view. It will list the total number of units in this game. Once this reaches 500 and more check your servers' load (using standard Linux/unix utilities like top, psfree, iotop etc.) to see how it handles this game and to get an idea how games will feel for players on your server. Note that this setup is close to maxing things out, so things may get a bit slow here and there, but the game should not fail.

As soon as all network players disconnect from your new gameserver, the gameserver should exit, so you should see your shells' prompt again. If this does not happen, you can type quit into the terminal window which presents your gameservers secure shell, and press Enter. If the game still does not quit then, try Ctrl-C or run this in a separate shell on the server:

kill -9 `pidof megaglest`

Game server automationEdit

If you want to run the game server regularly, you can introduce some level of automation. You may want to make it start up automatically on boot. And, while we are not aware of any, to rule out side effects which may drain on system resources, you should have the game quit and restart after every played game. After all, restarting the game is very quick and does not hurt.

Why not initd?Edit

The common Unix way of managing daemons is sysv-initd and its various derived approaches such as upstart and systemd, which are often not compatible. So if you wanted to write an initd-like script for MegaGlest, you would have to do it for every initd-like mechanisms which is in use these days.

You should also keep in mind that initd's concept is that you start a daemon process (storing its single process ID as a reference) and keep it running until you manually stop it through initd (effectively killing the process by its stored process ID). That's quite different to a daemon restarting itself regularly, getting a new process ID assigned each time it restarts, as should be the case for a MegaGlest game server. Howwever, this could still be done with an intermediary control / process monitoring layer, basically like a master process spawnings and killing its child processes, representing itself to initd-like daemon as a sincle process with a static process ID,

Finally, managing an initd-controlled process requires root access (which you may not have at any given time if you are not the sole user of thie server).

As a result of these thoughts, no initd-like scripts are provided for MegaGlest at this time. We would appreciate contributions under compatible license terms if you are willing to maintain it, though.

For now, there are other options, as discussed below.

Using CrondEdit

The easiest and most simple way to manage your headless server is to use the wrapper script  start_megaglest_gameserver which ships with MegaGlest. This script starts MegaGlest as a headless server and makes it quit after each played game.

The only thing missing then is a machanism to start this script automatically during boot of the server. This can be achieved by a crontab. To install it, working as the user which runs the gamserver, use

crontab -e

to spawn the crontab editor, then add this:

@reboot $HOME/megaglest-server/start_megaglest_gameserver >/dev/null

You may also want to set the MAIL variable on top of this file to ensure you receive email notifications in case of an error.

With this script in place, server logs are created at ~/.megaglest/server.log and can grow massively. You may want to rotate and/or compress them (or not create them in the first place).

After the next reboot, the gameserver should start up automatically.

Using restartdEdit

restartd is a simple job control system which does not interfere with your distributions' initd-like mechanism, but adds to it. So far it is mostly used on (and packaged for) Debian GNU/Linux but it is by no means limited to it.

Status reportingEdit

For scripting the server and making information on it available, such as on a website, you may want to be able to query the current state of the server at any given time. Starting with v3.7.0 you can query a headless server on TCP port 61355 (that's by default, use z in --use-ports=x,y,z when starting the server to listen on a custom port) on localhost ( only. To do so, either start a second MegaGlest instance using --headless-server-status (and optionally --use-ports, too) or just use a simple TCP client such as netcat (nc), telnet, sox, or even your web browser to connect to this port.

The output you will get will look something like this:

Headless Server Current Game information:
Network connection for index: 0
Connected: 0
Handshake received: 0
Network connection for index: 1
Connected: 1
Handshake received: 1
Connected at: 2012-10-17 01:04:36
Connection duration: 0 hours 0 minutes 29 seconds.
Player Index: 1
IP Address:
Player name: tomreyn
Language: english
Game Version: v3.7.0-dev-GNUC: 40603 [64bit]-Rev: 3724
Session id: 676319
Socket id: 7
Total Slot Count: 2

The reason this information is not available to the outside world by default is because it could stress the server (the server needs to handle these requests live at the same time a monstrous game may be going) but also to protect the players' privacy (it gives away IP addresses, language preference and system architecture of all connected players). This behaviour may change in the future. You, as a server admin, could already make it (or a subset of it) availabe now by either firewall rules (such as by forwarding inboound traffic on <external-ip>:61355 to or by means of a web server, which either proxies requests to (apache + mod_proxy) or provides access to a simple CGI script which wraps the output of --headless-server-status and adds HTTP headers to it.

Questions and feedbackEdit

If you have any questions, please discuss them at Please report both your positive and negative experiences there, too.

Running a game server, it is relatively easy to gather information about problems in MegaGlest. If you run into any bugs, please report them at

See alsoEdit

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.