Skip to content

Commit

Permalink
Add persistent server storage with MongoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowNinja committed Jan 23, 2016
1 parent 2fdd0da commit f514046
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 179 deletions.
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Setting up the webpage
----------------------

You will have to install node.js, doT.js and their dependencies to compile
the serverlist webpage template.
the server list webpage template.

First install node.js, e.g.:

Expand Down Expand Up @@ -62,10 +62,10 @@ Setting up the server
# # OR:
# apt-get install python3 python3-pip

2. Install Flask, and APScheduler:
2. Install required Python packages:

# # You might have to use pip3 if your system defaults to Python 2
# pip install APScheduler flask
# pip install -r requirements.txt

3. If using in production, install uwsgi and it's python plugin:

Expand All @@ -75,16 +75,31 @@ Setting up the server
# # OR:
# pip install uwsgi

4. Configure the server by changing options in config.py, which is a Flask
configuration file.
4. Install, start, and enable MongoDB on boot:

5. Start the server:
# pacman -S mongodb && systemctl enable mongodb --now

5. Configure the server by adding options to `config.py`.
See `config-example.py` for defaults.

6. Start the server:

$ ./server.py
$ # Or for production:
$ uwsgi -s /tmp/serverlist.sock --plugin python -w server:app --enable-threads
$ uwsgi -s /tmp/minetest-master.sock --plugin python -w server:app --enable-threads
$ # Then configure according to http://flask.pocoo.org/docs/deploying/uwsgi/

7. (optional) Configure the proxy server, if any. You should make the server
load static files directly from the static directory. Also, `/list`
should be served from `list.json`. Example for nginx:

root /path/to/server/static;
rewrite ^/list$ /list.json;
try_files $uri @uwsgi;
location @uwsgi {
uwsgi_pass ...;
}

License
-------

Expand Down
33 changes: 17 additions & 16 deletions config-example.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
from datetime import timedelta

# Enables detailed tracebacks and an interactive Python console on errors.
# Never use in production!
#DEBUG = True
DEBUG = False

# Address for development server to listen on
#HOST = "127.0.0.1"
HOST = "127.0.0.1"
# Port for development server to listen on
#PORT = 5000
PORT = 5000

# Makes the server more performant at sending static files when the
# server is being proxied by a server that supports X-Sendfile.
#USE_X_SENDFILE = True
# Amount of time after which servers are removed from the list if they haven't
# updated their listings. Note: By default Minetest servers only announce
# once every 5 minutes, so this should be more than that.
UPDATE_TIME = timedelta(minutes=6)

# File to store the JSON server list data in.
FILENAME = "list.json"

# Amount of time, is seconds, after which servers are removed from the list
# if they haven't updated their listings. Note: By default Minetest servers
# only announce once every 5 minutes, so this should be more than 300.
PURGE_TIME = 350

# List of banned IP addresses
BANLIST = []
# Amount of time after which servers are removed from the database if they
# haven't updated their listings.
PURGE_TIME = timedelta(days=30)

# Creates server entries if a server sends an 'update' and there is no entry yet.
# This should only be used to populate the server list after list.json was deleted.
# This WILL cause problems such as mapgen, mods and privilege information missing from the list
ALLOW_UPDATE_WITHOUT_OLD = False

# Number of days' data to factor into popularity calculation
POP_DAYS = 3

# Address of the MongoDB server. You can use domain sockets on unix.
MONGO_URI = "mongodb://localhost/minetest-master"

4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
APScheduler>=3
Flask>=0.10
Flask-PyMongo>=0.3

Loading

0 comments on commit f514046

Please sign in to comment.