Whole dang revamp of the codebase!
This commit is contained in:
parent
9510a82e3d
commit
bcef3596ad
8 changed files with 101 additions and 51 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -144,4 +144,8 @@ src/build/
|
|||
|
||||
pyvenv.cfg
|
||||
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
|
||||
*.dist
|
||||
*.build
|
||||
*.bin
|
||||
|
|
@ -1 +0,0 @@
|
|||
gcc -Os -I /opt/homebrew/Frameworks/Python.framework/Versions/3.9/include/python3.9 main.c -L /opt/homebrew/Frameworks/Python.framework/Versions/3.9/lib -lpython3.9 -o main
|
||||
31
readme.md
Normal file
31
readme.md
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Docker Minecraft Server Manager (DMSM)
|
||||
|
||||
## Overview
|
||||
|
||||
DMSM is a docker-powered server management system that makes creating a new server very easy to do. This is based off of itzg's [minecraft-server](https://hub.docker.com/r/itzg/minecraft-server) docker image, but with a configuration tool and CLI based around it.
|
||||
|
||||
DMSM is for **Unix Systems Only**. I have compiled it for macOS (both ARM and x86) as well as for Linux (x86-64 only), as Windows users should be using Linux under WSL (with Docker) for the ideal Windows server setup.
|
||||
|
||||
## Installation
|
||||
|
||||
### Requirements
|
||||
|
||||
The only requirement for using this is Docker. The application is written in Python but compiled to an executible, so you don't even need Python. All you need is docker, which you can find how to set up [here]https://docs.docker.com/get-docker/).
|
||||
|
||||
### Install
|
||||
|
||||
After that, download the right executible for you in the [Releases Page](https://github.com/oitsjustjose/DMSM/releases), move it to wherever you keep things (like `/usr/local/bin` for unix-based systems)
|
||||
|
||||
## Building
|
||||
|
||||
Building this tool is straight forward. What you'll need:
|
||||
|
||||
- Python 3.6 -- **this version is specific**
|
||||
- Pip for Python 3.6
|
||||
- Pip Packages described in `requirements.txt` (you can install them via `pip install -r requirements.txt`)
|
||||
|
||||
All you have to do once you have the dependencies handled is to run `python3 -m nuitka --standalone --onefile dmsm.py` from within the `src` folder.
|
||||
|
||||
## Running
|
||||
|
||||
The CLI will help you do this -- give me a bit and I'll write up more docs on this!
|
||||
|
|
@ -1,23 +1,54 @@
|
|||
appdirs==1.4.4
|
||||
argcomplete==1.12.1
|
||||
asn1crypto==0.24.0
|
||||
astroid==2.5.6
|
||||
black==21.5b2
|
||||
certifi==2021.5.30
|
||||
chardet==4.0.0
|
||||
click==8.0.1
|
||||
coverage==5.3
|
||||
cryptography==2.1.4
|
||||
Cython==0.29.23
|
||||
dataclasses==0.8
|
||||
distlib==0.3.1
|
||||
docker==5.0.0
|
||||
filelock==3.0.12
|
||||
flake8==3.8.4
|
||||
hjson==3.0.2
|
||||
idna==2.10
|
||||
importlib-metadata==2.0.0
|
||||
importlib-resources==3.0.0
|
||||
isort==5.8.0
|
||||
keyring==10.6.0
|
||||
keyrings.alt==3.0
|
||||
lazy-object-proxy==1.6.0
|
||||
mccabe==0.6.1
|
||||
milc==1.0.10
|
||||
mypy-extensions==0.4.3
|
||||
nose2==0.9.2
|
||||
Nuitka==0.6.15.3
|
||||
pathspec==0.8.1
|
||||
pipenv==2020.8.13
|
||||
pycodestyle==2.6.0
|
||||
pycrypto==2.6.1
|
||||
pyflakes==2.2.0
|
||||
Pygments==2.7.2
|
||||
pygobject==3.26.1
|
||||
pylint==2.8.3
|
||||
pyxdg==0.25
|
||||
qmk==0.0.36
|
||||
regex==2021.4.4
|
||||
requests==2.25.1
|
||||
rope==0.19.0
|
||||
# six==1.16.0
|
||||
SecretStorage==2.3.1
|
||||
six==1.16.0
|
||||
toml==0.10.2
|
||||
typed-ast==1.4.2
|
||||
typing-extensions==3.7.4.3
|
||||
urllib3==1.26.5
|
||||
virtualenv==20.0.35
|
||||
virtualenv-clone==0.5.4
|
||||
websocket-client==1.0.1
|
||||
wrapt==1.12.1
|
||||
yapf==0.30.0
|
||||
zipp==3.3.1
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ Author: Jose Stovall | oitsjustjose
|
|||
import argparse
|
||||
import sys
|
||||
|
||||
from docker_mgr import DockerManager
|
||||
from docker_mgr import ServerManager
|
||||
from logger import Logger
|
||||
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ def get_args() -> argparse.Namespace:
|
|||
(argparse.NameSpace) the arguments for the program
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Arguments for DockerPM",
|
||||
description="Arguments for Docker Minecraft Server Management (DMSM)",
|
||||
)
|
||||
|
||||
if len(sys.argv) >= 2 and sys.argv[1] == "create":
|
||||
|
|
@ -29,6 +29,7 @@ def get_args() -> argparse.Namespace:
|
|||
"-p",
|
||||
"--port",
|
||||
help="The port to run the newly created server on",
|
||||
default="25565",
|
||||
required=True,
|
||||
)
|
||||
parser.add_argument(
|
||||
|
|
@ -53,8 +54,8 @@ def get_args() -> argparse.Namespace:
|
|||
"-m",
|
||||
"--memory",
|
||||
help="The amount of dedicated memory for the server",
|
||||
required=False,
|
||||
default="2G",
|
||||
required=False,
|
||||
)
|
||||
|
||||
if len(sys.argv) >= 2 and sys.argv[1] in ["stop", "restart"]:
|
||||
|
|
@ -86,16 +87,10 @@ def main(args: argparse.Namespace) -> None:
|
|||
|
||||
action = sys.argv[1]
|
||||
server_name = sys.argv[2]
|
||||
mgr = DockerManager(server_name)
|
||||
mgr = ServerManager(server_name)
|
||||
|
||||
if action == "create":
|
||||
mgr.create_server(
|
||||
version=args.version,
|
||||
port=args.port,
|
||||
root=args.root,
|
||||
motd=args.motd,
|
||||
maxr=args.memory,
|
||||
)
|
||||
mgr.create_server(args)
|
||||
elif action == "start":
|
||||
mgr.start_server()
|
||||
elif action == "stop":
|
||||
|
|
@ -104,6 +99,10 @@ def main(args: argparse.Namespace) -> None:
|
|||
mgr.restart_server(force=args.force)
|
||||
elif action == "delete":
|
||||
mgr.delete_server()
|
||||
elif action == "status":
|
||||
mgr.get_status()
|
||||
elif action == "console":
|
||||
mgr.open_console()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
@ -4,14 +4,14 @@ Author: Jose Stovall | oitsjustjose
|
|||
# pylint: disable=broad-except, bare-except
|
||||
|
||||
import os
|
||||
from typing import Union
|
||||
from argparse import Namespace
|
||||
|
||||
import docker
|
||||
|
||||
from logger import Logger
|
||||
|
||||
|
||||
class DockerManager:
|
||||
class ServerManager:
|
||||
"""
|
||||
A Management system for a docker container
|
||||
"""
|
||||
|
|
@ -34,26 +34,26 @@ class DockerManager:
|
|||
"""
|
||||
return self._client
|
||||
|
||||
def create_server(
|
||||
self, version: str, port: Union[int, str], root: str, motd="", maxr="2G"
|
||||
):
|
||||
def create_server(self, args: Namespace):
|
||||
"""
|
||||
Creates a new docker container
|
||||
"""
|
||||
try:
|
||||
if os.path.exists(root):
|
||||
self._log.warn(f"Server root '{root}' exists - there may be problems!")
|
||||
if os.path.exists(args.root):
|
||||
self._log.warn(
|
||||
f"Server root '{args.root}' exists - there may be problems!"
|
||||
)
|
||||
self._client.containers.run(
|
||||
"itzg/minecraft-server",
|
||||
name=self._name,
|
||||
ports={25565: port},
|
||||
ports={25565: args.port},
|
||||
environment={
|
||||
"VERSION": version,
|
||||
"VERSION": args.version,
|
||||
"EULA": True,
|
||||
"MOTD": motd,
|
||||
"MEMORY": maxr,
|
||||
"MOTD": args.motd,
|
||||
"MEMORY": args.maxr,
|
||||
},
|
||||
volumes={root: {"bind": "/data", "mode": "rw"}},
|
||||
volumes={args.root: {"bind": "/data", "mode": "rw"}},
|
||||
detach=True,
|
||||
)
|
||||
self._container = self._get_container()
|
||||
|
|
@ -111,3 +111,14 @@ class DockerManager:
|
|||
self._log.success("Successfully Restarted Server")
|
||||
except:
|
||||
self._log.err("Failed to Restart Server")
|
||||
|
||||
def get_status(self):
|
||||
"""
|
||||
Gets the status of a contianer
|
||||
"""
|
||||
self._log.info(self._container.status)
|
||||
|
||||
def open_console(self):
|
||||
"""
|
||||
Connects the user to the server's console
|
||||
"""
|
||||
25
src/setup.py
25
src/setup.py
|
|
@ -1,25 +0,0 @@
|
|||
"""
|
||||
Author: Jose Stovall | oitsjustjose
|
||||
"""
|
||||
|
||||
from setuptools import setup
|
||||
from Cython.Build import cythonize
|
||||
|
||||
import os
|
||||
|
||||
setup(
|
||||
ext_modules = cythonize("logger.pyx"),
|
||||
compiler_directives={'language_level' : "3"}
|
||||
)
|
||||
|
||||
setup(
|
||||
ext_modules = cythonize("docker_mgr.pyx"),
|
||||
compiler_directives={'language_level' : "3"}
|
||||
)
|
||||
|
||||
print("Moving files to outdir")
|
||||
|
||||
for file in os.listdir("."):
|
||||
if not os.path.isdir(file):
|
||||
if not (file.endswith(".py") or file.endswith(".pyx")):
|
||||
os.rename(file, f"./out/{file}")
|
||||
Loading…
Reference in a new issue