Skip to content

docent-net/mc-server-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mc-server-manager

The main goal of this project is to manage Minecraft server instances on a container / virtual machine / physical server having only 1 instance running at a time.

Requirements

  • Any systemd-powered Linux server with Minecraft server installed.
  • Python 3.8
  • Installed libraries from requirements.txt

Usage

via CLI:

  • enter backend directory
  • test script installation and configuration: ./manage.py test
  • activate specified server: ./manage.py activate --server_name=<server_name>
  • stop server: ./manage.py stop
  • start server: ./manage.py start
  • restart server: ./manage.py restart
  • secure server: ./manage.py secure --server_name=<server_name>
  • delete server: ./manage.py delete --server_name=<server_name>
  • create a new server from template: ./manage.py create --server_name=<server_name>

via API:

  • start server (will bind to 8000 port): cd backend; python app.py
  • api methods:
    • /health (GET)
    • /get_servers (GET)
    • /activate_server (POST, GET: <server_name=server_name>)
    • /delete_server (DELETE: <server_name=server_name>)
    • /create_server (PUT: <server_name=server_name>)
    • /restart_server (POST, GET)
    • /delete_server_instance/<server_name> (DELETE)

via UI:

UI UI

Installation and configuration

  1. clone this repository
  2. For backend/API server:
  3. copy minecraft-server.service to the **/USER_HOMEDIR/.config/systemd/user/minecraft-server.service
  4. edit above service file to match your environment and needs
  5. install required Python libraries (pip install --user -r requirements.txt)
  6. confirm everything works fine: cd backend; ./manage.py test - this should list all servers found in USER_HOMEDIR/servers-data directory as well as should display current state of the Minecraft server.
  7. copy config.ini.template to /USER_HOMEDIR/.minecraft/mc-manager-config and edit its contents to match your environment**
  8. run backend server: python app.py
  9. For frontend / UI
  10. Install prerequities: cd frontend-ui; npm install
  11. Create configuration for prod: 1. cp .env.template .env.production 1. edit .env.production and fill with prod values 1. run via: node_modules/.bin/vue-cli-service serve --mode production

High level overview

The main goal of this project is to provide user with a tool (CLI and UI) for managing many MC server instances within one Linux server instance.

Under the hood - how it works?

Main assumptions are:

  1. Linux server instance is powered with systemd
  2. Minecraft server is installed in /USER_HOMEDIR/minecraft-server
  3. Servers data directory is in /USER_HOMEDIR/servers-data
  4. There is also a copy of srv-template directory (provided in this repo) under /USER_HOMEDIR/srv-template
  5. A systemd unit service is created in /USER_HOMEDIR/.config/systemd/user/minecraft-server.service and managed by this user (without a need for elevated permissions)

Now, in order to create a new server scripts/API basically copy all files from srv_template to a new subdirectory under servers-data (e.g. servers-data/new-server).

In order to activate a server script will remove all symlinks from minecraft-server directory and create new ones pointing at servers-data/new-server. Afterwards it will restart minecraft-server.service service.

Server template

Server template is basically a list of files that are customized per server instance and belongs to a specific server instance. All other files (binaries, libraries) are common.

  • Server template files (that will be symlinked):
    • banned-ips.json
    • banned-players.json
    • bukkit.yml
    • commands.yml
    • crash-reports
    • logs ops.json
    • permissions.yml
    • server.properties
    • spigot.yml
    • usercache.json
    • whitelist.json
    • world
    • world_nether
    • world_the_end

Minecraft server versions

For now the whole machinery make a naive assumption that every server instance works on the same Minecraft server version.

Development

git hooks

There is a file git-hooks/pre-commit which contains pre-commit hooks used in this repo for running all required unit tests, lint checkers etc.

Copy it to .git/hooks/pre-commit in order to have it run on commit.

Same tests will be run before Pull-Request review.

Backend / API

All backend components are stored inside of backend directory.

For development purposes there is a minecraft-server-stub.service in this repo which might be used for testing various server scenarios.

API server uses Flask-API library.

Developing backend services requires Python 3.8 and libraries installed from requirements.txt. Using pyenv is recommended.

In order to start API server:

cd backend; python app.py

Above will start the server on 127.0.0.1:8000

Frontend / UI

UI uses vue.js library. All UI components are stored inside of frontend-ui directory.

In order to prepare your frontend development environment:

$ cd ftontend-ui
$ npm install
$ npm run server
# or directly via vue plugin:
$ node_modules/.bin/vue-cli-service serve --mode development

Now you should have your frontend service running in http://localhost:8080/