minecraft-server-creator 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- minecraft_server_creator-2.0.0/LICENSE +2 -0
- minecraft_server_creator-2.0.0/PKG-INFO +46 -0
- minecraft_server_creator-2.0.0/README.md +29 -0
- minecraft_server_creator-2.0.0/pyproject.toml +22 -0
- minecraft_server_creator-2.0.0/setup.cfg +4 -0
- minecraft_server_creator-2.0.0/src/mcsc/__init__.py +4 -0
- minecraft_server_creator-2.0.0/src/mcsc/__main__.py +7 -0
- minecraft_server_creator-2.0.0/src/mcsc/config/settings.py +45 -0
- minecraft_server_creator-2.0.0/src/mcsc/config/update_files.py +24 -0
- minecraft_server_creator-2.0.0/src/mcsc/localization/it.py +80 -0
- minecraft_server_creator-2.0.0/src/mcsc/main.py +102 -0
- minecraft_server_creator-2.0.0/src/mcsc/modules/classes.py +115 -0
- minecraft_server_creator-2.0.0/src/mcsc/modules/logger.py +107 -0
- minecraft_server_creator-2.0.0/src/mcsc/modules/pages.py +379 -0
- minecraft_server_creator-2.0.0/src/mcsc/modules/servers/forge.py +175 -0
- minecraft_server_creator-2.0.0/src/mcsc/modules/servers/java.py +13 -0
- minecraft_server_creator-2.0.0/src/mcsc/modules/servers/models.py +430 -0
- minecraft_server_creator-2.0.0/src/mcsc/modules/servers/paper.py +109 -0
- minecraft_server_creator-2.0.0/src/mcsc/modules/servers/utils.py +136 -0
- minecraft_server_creator-2.0.0/src/mcsc/modules/translations.py +47 -0
- minecraft_server_creator-2.0.0/src/mcsc/modules/user_settings.py +144 -0
- minecraft_server_creator-2.0.0/src/mcsc/modules/utils.py +735 -0
- minecraft_server_creator-2.0.0/src/mcsc/static/logo.png +0 -0
- minecraft_server_creator-2.0.0/src/mcsc/static/style.css +249 -0
- minecraft_server_creator-2.0.0/src/mcsc/tasks.py +152 -0
- minecraft_server_creator-2.0.0/src/mcsc/telemetry.py +99 -0
- minecraft_server_creator-2.0.0/src/mcsc/update.py +87 -0
- minecraft_server_creator-2.0.0/src/mcsc/utils.py +30 -0
- minecraft_server_creator-2.0.0/src/minecraft_server_creator.egg-info/PKG-INFO +46 -0
- minecraft_server_creator-2.0.0/src/minecraft_server_creator.egg-info/SOURCES.txt +32 -0
- minecraft_server_creator-2.0.0/src/minecraft_server_creator.egg-info/dependency_links.txt +1 -0
- minecraft_server_creator-2.0.0/src/minecraft_server_creator.egg-info/entry_points.txt +2 -0
- minecraft_server_creator-2.0.0/src/minecraft_server_creator.egg-info/requires.txt +4 -0
- minecraft_server_creator-2.0.0/src/minecraft_server_creator.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: minecraft-server-creator
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Minecraft Server Creator - Manage Minecraft servers
|
|
5
|
+
Author-email: ddavidel <ddavidel@proton.me>
|
|
6
|
+
License: This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
|
|
7
|
+
See https://creativecommons.org/licenses/by-nc-sa/4.0/ for more details.
|
|
8
|
+
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: nicegui
|
|
13
|
+
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: appdirs
|
|
15
|
+
Requires-Dist: pywebview
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
[](./LICENSE)
|
|
19
|
+
|
|
20
|
+

|
|
21
|
+
# MCSC - Minecraft Server Creator
|
|
22
|
+
MCSC is a user-friendly tool written in Python with a GUI that simplifies the process of creating and managing Minecraft servers. Whether you're a beginner or experienced, MCSC allows you to easily set up, run, and control multiple Minecraft servers from a single interface.
|
|
23
|
+
> **Warning**: MCSC is still in development, thus it may not be completely error free.
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
- **Create Multiple Servers**: Set up and manage multiple Minecraft servers from within the app.
|
|
27
|
+
- **Start/Stop Servers**: Easily start and stop your Minecraft servers directly from the GUI.
|
|
28
|
+
- **Console Interaction**: Read the console output in real-time and send commands to the Minecraft server console.
|
|
29
|
+
- **Edit server.properties**: Customize your Minecraft server settings by editing the `server.properties` file with a built-in editor.
|
|
30
|
+
- **User-Friendly GUI**: A simple and intuitive interface designed for both beginners and experienced users.
|
|
31
|
+
- **Manage Server Instances**: Keep track of all your servers in one place.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
To install and run MCSC on your local machine:
|
|
35
|
+
1. Clone the repository:
|
|
36
|
+
`git clone https://github.com/ddavidel/minecraft-server-creator.git`
|
|
37
|
+
|
|
38
|
+
2. Navigate to the project folder and install the required dependencies:
|
|
39
|
+
`pip install -r requirements.txt`
|
|
40
|
+
|
|
41
|
+
3. Run the application by double clicking `START.bat` or with the following command:
|
|
42
|
+
`python ServerCreator.py`
|
|
43
|
+
|
|
44
|
+
## Upcoming Features
|
|
45
|
+
- **Support for more server types**: In the future updates, MCSC will support creating and managing many popular Minecraft server types.
|
|
46
|
+
- **Plugin and Mod Manager**: Easily manage plugins and mods.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[](./LICENSE)
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
# MCSC - Minecraft Server Creator
|
|
5
|
+
MCSC is a user-friendly tool written in Python with a GUI that simplifies the process of creating and managing Minecraft servers. Whether you're a beginner or experienced, MCSC allows you to easily set up, run, and control multiple Minecraft servers from a single interface.
|
|
6
|
+
> **Warning**: MCSC is still in development, thus it may not be completely error free.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
- **Create Multiple Servers**: Set up and manage multiple Minecraft servers from within the app.
|
|
10
|
+
- **Start/Stop Servers**: Easily start and stop your Minecraft servers directly from the GUI.
|
|
11
|
+
- **Console Interaction**: Read the console output in real-time and send commands to the Minecraft server console.
|
|
12
|
+
- **Edit server.properties**: Customize your Minecraft server settings by editing the `server.properties` file with a built-in editor.
|
|
13
|
+
- **User-Friendly GUI**: A simple and intuitive interface designed for both beginners and experienced users.
|
|
14
|
+
- **Manage Server Instances**: Keep track of all your servers in one place.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
To install and run MCSC on your local machine:
|
|
18
|
+
1. Clone the repository:
|
|
19
|
+
`git clone https://github.com/ddavidel/minecraft-server-creator.git`
|
|
20
|
+
|
|
21
|
+
2. Navigate to the project folder and install the required dependencies:
|
|
22
|
+
`pip install -r requirements.txt`
|
|
23
|
+
|
|
24
|
+
3. Run the application by double clicking `START.bat` or with the following command:
|
|
25
|
+
`python ServerCreator.py`
|
|
26
|
+
|
|
27
|
+
## Upcoming Features
|
|
28
|
+
- **Support for more server types**: In the future updates, MCSC will support creating and managing many popular Minecraft server types.
|
|
29
|
+
- **Plugin and Mod Manager**: Easily manage plugins and mods.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "minecraft-server-creator"
|
|
7
|
+
version = "2.0.0"
|
|
8
|
+
description = "Minecraft Server Creator - Manage Minecraft servers"
|
|
9
|
+
authors = [{ name = "ddavidel", email = "ddavidel@proton.me" }]
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
dependencies = ["nicegui", "requests", "appdirs", "pywebview"]
|
|
13
|
+
requires-python = ">=3.12"
|
|
14
|
+
|
|
15
|
+
[tool.setuptools]
|
|
16
|
+
package-dir = { "" = "src" }
|
|
17
|
+
|
|
18
|
+
[project.scripts]
|
|
19
|
+
mcsc = "mcsc.__main__:main"
|
|
20
|
+
|
|
21
|
+
[tool.setuptools.package-data]
|
|
22
|
+
"mcsc" = ["static/*", "static/**/*"]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Settings"""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from appdirs import user_data_dir
|
|
5
|
+
from mcsc.modules.user_settings import UserSettings
|
|
6
|
+
_user_settings = UserSettings().user_settings
|
|
7
|
+
|
|
8
|
+
DEBUG=False
|
|
9
|
+
# MISC APP SETTINGS
|
|
10
|
+
VERSION_FILENAME = "VERSION.txt"
|
|
11
|
+
GITHUB_REPO = "ddavidel/minecraft-server-creator"
|
|
12
|
+
UPDATE_BRANCH = "main" # "main", "develop"
|
|
13
|
+
GITHUB_FILE_URL = f"https://raw.githubusercontent.com/{GITHUB_REPO}/refs/heads/{UPDATE_BRANCH}/{VERSION_FILENAME}"
|
|
14
|
+
DATA_DIR_PATH = user_data_dir("mcsc")
|
|
15
|
+
BACKUP_DIR = os.path.join(DATA_DIR_PATH, "backups")
|
|
16
|
+
LOG_DIR_PATH = os.path.join(DATA_DIR_PATH, "logs")
|
|
17
|
+
TELEMETRY_DIR_PATH = os.path.join(DATA_DIR_PATH, "telemetry")
|
|
18
|
+
TELEMETRY_API = "https://mcscreator.altervista.org/telemetry/receiver.php"
|
|
19
|
+
PACKAGE_NAME = "minecraft-server-creator"
|
|
20
|
+
PYPI_PACKAGE_URL = f"https://pypi.org/pypi/{PACKAGE_NAME}/json"
|
|
21
|
+
|
|
22
|
+
# DB
|
|
23
|
+
BACKEND = "json"
|
|
24
|
+
USER_SETTINGS_FILENAME = "user_settings.json"
|
|
25
|
+
USER_SETTINGS_PATH = os.path.join(DATA_DIR_PATH, "config")
|
|
26
|
+
USER_SETTINGS_FILE_PATH = os.path.join(USER_SETTINGS_PATH, USER_SETTINGS_FILENAME)
|
|
27
|
+
|
|
28
|
+
# TRANSLATION SETTINGS
|
|
29
|
+
DEFAULT_LANGUAGE = _user_settings.get("language", "en")
|
|
30
|
+
AVAILABLE_LANGAGUES = ["en", "it"]
|
|
31
|
+
|
|
32
|
+
# SERVERS SETTINGS
|
|
33
|
+
SERVER_DIR_PATH = os.path.join(DATA_DIR_PATH, "servers")
|
|
34
|
+
SERVERS_JSON_PATH = os.path.join(DATA_DIR_PATH, "config", "servers.json")
|
|
35
|
+
JAR_VERSIONS_FILTER = "stable" # "stable", "none"
|
|
36
|
+
MAX_LOG_LINES = 300
|
|
37
|
+
|
|
38
|
+
# SERVER EXECUTION SETTINGS
|
|
39
|
+
JAVA_BIT_MODEL = "64"
|
|
40
|
+
NOGUI = True
|
|
41
|
+
|
|
42
|
+
# URLS
|
|
43
|
+
VANILLA_VERSION_LIST_URL = "https://raw.githubusercontent.com/ddavidel/minecraft-server-jars/refs/heads/main/versions/vanilla_version_list.json"
|
|
44
|
+
FORGE_VERSION_LIST_URL = "https://raw.githubusercontent.com/ddavidel/minecraft-forge-links/refs/heads/main/version_list.json"
|
|
45
|
+
PAPER_VERSION_LIST_URL = "https://raw.githubusercontent.com/ddavidel/minecraft-server-jars/refs/heads/main/versions/paper_version_list.json"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Update files
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
UPDATE_FILES = [
|
|
6
|
+
{"filename": "pages.py", "path": "modules"},
|
|
7
|
+
{"filename": "ServerCreator.py", "path": ""},
|
|
8
|
+
{"filename": "settings.py", "path": "config"},
|
|
9
|
+
{"filename": "update.py", "path": ""},
|
|
10
|
+
{"filename": "utils.py", "path": "modules"},
|
|
11
|
+
{"filename": "style.css", "path": "static"},
|
|
12
|
+
{"filename": "requirements.txt", "path": ""},
|
|
13
|
+
{"filename": "VERSION.txt", "path": ""},
|
|
14
|
+
{"filename": "it.py", "path": "localization"},
|
|
15
|
+
{"filename": "translations.py", "path": "modules"},
|
|
16
|
+
{"filename": "user_settings.py", "path": "modules"},
|
|
17
|
+
{"filename": "classes.py", "path": "modules"},
|
|
18
|
+
{"filename": "forge.py", "path": "modules/servers"},
|
|
19
|
+
{"filename": "java.py", "path": "modules/servers"},
|
|
20
|
+
{"filename": "utils.py", "path": "modules/servers"},
|
|
21
|
+
{"filename": "models.py", "path": "modules/servers"},
|
|
22
|
+
{"filename": "logger.py", "path": "modules"},
|
|
23
|
+
{"filename": "paper.py", "path": "modules/servers"},
|
|
24
|
+
]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Italian translations
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
translations = {
|
|
6
|
+
"Create Server": "Crea Server",
|
|
7
|
+
"Start": "Avvia",
|
|
8
|
+
"Settings": "Impostazioni",
|
|
9
|
+
"Console": "Terminale",
|
|
10
|
+
"Edit server settings": "Modifica impostazioni",
|
|
11
|
+
"Edit server properties": "Modifica proprietà",
|
|
12
|
+
"Delete server": "Elimina server",
|
|
13
|
+
"Your servers": "I tuoi server",
|
|
14
|
+
"Seems like you don't have any. Let's create one!": "Sembra tu non ne abbia. Creane uno!",
|
|
15
|
+
"Save": "Salva",
|
|
16
|
+
"Starting": "Avviando",
|
|
17
|
+
"Stopping": "Stoppando",
|
|
18
|
+
"Running": "In esecuzione",
|
|
19
|
+
"Stopped": "Spento",
|
|
20
|
+
"Invalid server": "Server invalido",
|
|
21
|
+
"Write command": "Scrivi comando",
|
|
22
|
+
"Status: {value}": "Stato: {value}",
|
|
23
|
+
"Starting creation of server {name}": "Avvio creazione server {name}",
|
|
24
|
+
"Server name can't be empty": "Il nome del server non può essere vuoto",
|
|
25
|
+
"Server created!": "Server creato!",
|
|
26
|
+
"New Server": "Nuovo Server",
|
|
27
|
+
"Server name": "Nome del server",
|
|
28
|
+
"Accept EULA (Required)": "Accetta EULA (Richiesto)",
|
|
29
|
+
"Dedicated RAM": "RAM dedicata",
|
|
30
|
+
"Other settings": "Altre impostazioni",
|
|
31
|
+
"Server Type": "Tipo di server",
|
|
32
|
+
"Server Version": "Versione del server",
|
|
33
|
+
"Cancel": "Annulla",
|
|
34
|
+
"Create": "Crea",
|
|
35
|
+
"Version URL not found": "URL versione non trovato",
|
|
36
|
+
"Saving settings of server '{name}'": "Salvataggio impostazioni del server '{name}'",
|
|
37
|
+
"Settings saved!": "Impostazioni salvate!",
|
|
38
|
+
"Edit Server": "Modifica Server",
|
|
39
|
+
"Too long!": "Troppo lungo!",
|
|
40
|
+
"Suggested for this device: {value} GB": "Suggerito per questo dispositivo: {value} GB",
|
|
41
|
+
"Deleting server {name}": "Eliminazione server {name}",
|
|
42
|
+
"Server deleted": "Server eliminato",
|
|
43
|
+
"Are you sure?": "Sei sicuro?",
|
|
44
|
+
"Write '{name}' below to confirm": "Scrivi '{name}' qui sotto per confermare",
|
|
45
|
+
"Confirm name": "Conferma nome",
|
|
46
|
+
"Wrong name": "Nome sbagliato",
|
|
47
|
+
"Delete server folder": "Elimina cartella del server",
|
|
48
|
+
"Delete": "Elimina",
|
|
49
|
+
"Server version can't be empty": "La versione del server non può essere vuota",
|
|
50
|
+
"Some settings require a restart to take effect. Please restart the app after changing them.": "Alcune impostazioni richiedono un riavvio per avere effetto. Si prega di riavviare l'app dopo averle cambiate.",
|
|
51
|
+
"Close": "Chiudi",
|
|
52
|
+
"Language": "Lingua",
|
|
53
|
+
"Unsupported Forge Version. THIS IS NOT A BUG!": "Versione di Forge non supportata. QUESTO NON È UN BUG!",
|
|
54
|
+
"Creating server {name}": "Creazione server {name}",
|
|
55
|
+
"Open server folder": "Apri cartella del server",
|
|
56
|
+
"RAM usage": "Utilizzo RAM",
|
|
57
|
+
"CPU usage": "Utilizzo CPU",
|
|
58
|
+
"Disk read": "Lettura disco",
|
|
59
|
+
"Disk write": "Scrittura disco",
|
|
60
|
+
"Back": "Indietro",
|
|
61
|
+
"Update available": "Aggiornamento disponibile",
|
|
62
|
+
"Check for updates": "Controlla aggiornamenti",
|
|
63
|
+
"App Settings": "Impostazioni App",
|
|
64
|
+
"No updates available": "Nessun aggiornamento disponibile",
|
|
65
|
+
"Checking for updates...": "Controllo aggiornamenti...",
|
|
66
|
+
"Update complete. Restart the app": "Aggiornamento completato. Riavvia l'app",
|
|
67
|
+
"Updating": "Aggiornamento in corso",
|
|
68
|
+
"Something went wrong": "Qualcosa è andato storto",
|
|
69
|
+
"MCSC Settings": "Impostazioni MCSC",
|
|
70
|
+
"Coming soon": "Prossimamente",
|
|
71
|
+
"Version: {version}": "Versione: {version}",
|
|
72
|
+
"Update Now": "Aggiorna Ora",
|
|
73
|
+
"A new version of the app is available. Do you want to update now?": "È disponibile una nuova versione dell'app. Vuoi aggiornare ora?",
|
|
74
|
+
"Later": "Dopo",
|
|
75
|
+
"Saving": "Salvataggio in corso",
|
|
76
|
+
"Settings saved": "Impostazioni salvate",
|
|
77
|
+
"There are still servers running. Are you sure you want to quit?" : "Ci sono ancora server in esecuzione. Sei sicuro di voler uscire?",
|
|
78
|
+
"No, take me back": "No, riportami indietro",
|
|
79
|
+
"Yes, quit": "Si, esci",
|
|
80
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""Main"""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import shutil
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from nicegui import ui, html, app
|
|
7
|
+
|
|
8
|
+
from mcsc.modules.pages import (
|
|
9
|
+
build_base_window,
|
|
10
|
+
build_drawer,
|
|
11
|
+
home,
|
|
12
|
+
)
|
|
13
|
+
from mcsc.modules.servers.utils import load_servers, TYPE_TO_CLASS
|
|
14
|
+
from mcsc.modules.utils import load_server_versions
|
|
15
|
+
from mcsc.utils import static_dir
|
|
16
|
+
from mcsc.telemetry import TelemetryClient
|
|
17
|
+
from mcsc.config.settings import DATA_DIR_PATH, SERVER_DIR_PATH
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
app.native.window_args["resizable"] = False
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ServerCreatorGUI:
|
|
24
|
+
"""Main class"""
|
|
25
|
+
|
|
26
|
+
def __init__(self):
|
|
27
|
+
"""
|
|
28
|
+
Loads stuff.
|
|
29
|
+
IMPORTANT: Order matters.
|
|
30
|
+
"""
|
|
31
|
+
self.telemetry_client = TelemetryClient()
|
|
32
|
+
app.add_static_files("/static", str(static_dir))
|
|
33
|
+
# Load server (creates servers.json file if not found)
|
|
34
|
+
load_servers()
|
|
35
|
+
load_server_versions()
|
|
36
|
+
self.migrate_legacy()
|
|
37
|
+
|
|
38
|
+
def run(self):
|
|
39
|
+
"""Main"""
|
|
40
|
+
self.telemetry_client.send_event(event_name="app_start")
|
|
41
|
+
# Prepare components
|
|
42
|
+
header = ui.header().classes("content-header")
|
|
43
|
+
container = html.section()
|
|
44
|
+
|
|
45
|
+
# Build view
|
|
46
|
+
build_base_window(header=header)
|
|
47
|
+
build_drawer()
|
|
48
|
+
home(header=header, container=container)
|
|
49
|
+
|
|
50
|
+
ui.run(
|
|
51
|
+
native=True,
|
|
52
|
+
window_size=(1300, 800),
|
|
53
|
+
reload=False,
|
|
54
|
+
title="Minecraft Server Creator",
|
|
55
|
+
dark=True,
|
|
56
|
+
frameless=True,
|
|
57
|
+
show=False,
|
|
58
|
+
reconnect_timeout=60,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def migrate_legacy(self):
|
|
62
|
+
"""Perform migration from legacy to new version"""
|
|
63
|
+
# pylint: disable=unspecified-encoding
|
|
64
|
+
# Check if there is a migration file: 'migration.mgr' in data dir
|
|
65
|
+
migration_file = Path(DATA_DIR_PATH) / "migration.mgr"
|
|
66
|
+
|
|
67
|
+
if migration_file.exists():
|
|
68
|
+
# Perform migration
|
|
69
|
+
|
|
70
|
+
print("Detected servers migration for legacy version of MCSC")
|
|
71
|
+
legacy_servers_json: str = migration_file.read_text().strip()
|
|
72
|
+
legacy_servers_dict: dict = json.loads(
|
|
73
|
+
Path(legacy_servers_json).read_text()
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
for server_uuid, config in legacy_servers_dict.items():
|
|
77
|
+
print(f"Migrating server '{server_uuid}' ({config['name']})...")
|
|
78
|
+
|
|
79
|
+
server_folder = config["folder_path"]
|
|
80
|
+
|
|
81
|
+
# Copy server folder into SERVER_DIR_PATH
|
|
82
|
+
new_server_folder: Path = Path(SERVER_DIR_PATH) / server_uuid
|
|
83
|
+
if not new_server_folder.exists():
|
|
84
|
+
shutil.copytree(server_folder, new_server_folder)
|
|
85
|
+
else:
|
|
86
|
+
# This could happen if the user starts the legacy version
|
|
87
|
+
# after completing the migration.
|
|
88
|
+
continue
|
|
89
|
+
|
|
90
|
+
# Update server config path
|
|
91
|
+
config["folder_path"] = str(new_server_folder)
|
|
92
|
+
|
|
93
|
+
# Saving the migrated server in the servers.json file
|
|
94
|
+
# instance = MinecraftServer(settings=config, uuid=server_uuid)
|
|
95
|
+
instance = TYPE_TO_CLASS[config["jar_type"]](
|
|
96
|
+
settings=config, uuid=server_uuid
|
|
97
|
+
)
|
|
98
|
+
instance.save()
|
|
99
|
+
|
|
100
|
+
# Rename migration file to 'migration.mgr.done'
|
|
101
|
+
migration_file.rename(migration_file.with_suffix(".mgr.done"))
|
|
102
|
+
print("Migration completed successfully.")
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Classes
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import psutil
|
|
7
|
+
|
|
8
|
+
from mcsc.modules.logger import RotatingLogger
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
logger = RotatingLogger()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ProcessMonitor:
|
|
15
|
+
"""
|
|
16
|
+
Monitor a process system resource usage
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, process=None, interval: int = 1):
|
|
20
|
+
self.process = process
|
|
21
|
+
self.interval = interval
|
|
22
|
+
self.active = False
|
|
23
|
+
self.ram_usage = 0
|
|
24
|
+
self.cpu_usage = 0
|
|
25
|
+
self.disk_read = 0
|
|
26
|
+
self.disk_write = 0
|
|
27
|
+
logger.info(f"{self} initialized")
|
|
28
|
+
|
|
29
|
+
def __repr__(self):
|
|
30
|
+
if self.process:
|
|
31
|
+
return f"ProcessMonitor(pid={self.process.pid}, active={self.active})"
|
|
32
|
+
return f"ProcessMonitor(active={self.active})"
|
|
33
|
+
|
|
34
|
+
def stop(self):
|
|
35
|
+
"""Stop monitoring the process"""
|
|
36
|
+
self.active = False
|
|
37
|
+
self.ram_usage = 0
|
|
38
|
+
self.cpu_usage = 0
|
|
39
|
+
self.disk_read = 0
|
|
40
|
+
self.disk_write = 0
|
|
41
|
+
logger.info(f"{self} stopped")
|
|
42
|
+
|
|
43
|
+
async def run(self):
|
|
44
|
+
"""Start monitoring the process"""
|
|
45
|
+
if not self.process:
|
|
46
|
+
logger.warning("No process to monitor. Use the 'process' attribute to set one.")
|
|
47
|
+
return
|
|
48
|
+
|
|
49
|
+
if self.active:
|
|
50
|
+
return
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
proc = psutil.Process(self.process.pid)
|
|
54
|
+
|
|
55
|
+
prev_disk_read = 0
|
|
56
|
+
prev_disk_write = 0
|
|
57
|
+
|
|
58
|
+
logger.info(f"{self} started")
|
|
59
|
+
|
|
60
|
+
while self.process.returncode is None:
|
|
61
|
+
self.active = True
|
|
62
|
+
# Get all child processes
|
|
63
|
+
children = proc.children(recursive=True)
|
|
64
|
+
|
|
65
|
+
# RAM usage in MB (sum of parent and children)
|
|
66
|
+
self.ram_usage = round(
|
|
67
|
+
(
|
|
68
|
+
proc.memory_info().rss
|
|
69
|
+
+ sum(child.memory_info().rss for child in children)
|
|
70
|
+
)
|
|
71
|
+
/ (1024 * 1024),
|
|
72
|
+
2,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# CPU usage as a percentage (sum of parent and children)
|
|
76
|
+
self.cpu_usage = round(
|
|
77
|
+
proc.cpu_percent(interval=0.1)
|
|
78
|
+
+ sum(child.cpu_percent(interval=0.1) for child in children),
|
|
79
|
+
2,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# Disk I/O (read and write in MB, current cycle)
|
|
83
|
+
io_counters = proc.io_counters()
|
|
84
|
+
current_disk_read = io_counters.read_bytes
|
|
85
|
+
current_disk_write = io_counters.write_bytes
|
|
86
|
+
for child in children:
|
|
87
|
+
child_io = child.io_counters()
|
|
88
|
+
current_disk_read += child_io.read_bytes
|
|
89
|
+
current_disk_write += child_io.write_bytes
|
|
90
|
+
|
|
91
|
+
# Calculate current cycle usage
|
|
92
|
+
self.disk_read = round(
|
|
93
|
+
(current_disk_read - prev_disk_read) / (1024 * 1024), 2
|
|
94
|
+
)
|
|
95
|
+
self.disk_write = round(
|
|
96
|
+
(current_disk_write - prev_disk_write) / (1024 * 1024), 2
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
# Update previous values
|
|
100
|
+
prev_disk_read = current_disk_read
|
|
101
|
+
prev_disk_write = current_disk_write
|
|
102
|
+
|
|
103
|
+
await asyncio.sleep(self.interval)
|
|
104
|
+
|
|
105
|
+
except psutil.NoSuchProcess:
|
|
106
|
+
logger.info("The process has exited.")
|
|
107
|
+
self.active = False
|
|
108
|
+
|
|
109
|
+
except Exception as e:
|
|
110
|
+
logger.error(f"Error monitoring process: {e}")
|
|
111
|
+
self.active = False
|
|
112
|
+
|
|
113
|
+
finally:
|
|
114
|
+
if self.active:
|
|
115
|
+
self.stop()
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Simple logger because i dont want to use logger module
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import datetime
|
|
7
|
+
import glob
|
|
8
|
+
from mcsc.config import settings as mcssettings
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class RotatingLogger:
|
|
12
|
+
"""
|
|
13
|
+
Simple logger that rotates logs daily and deletes old logs.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
LOG_RETENTION_DAYS = 0
|
|
17
|
+
|
|
18
|
+
def __init__(self, log_dir=mcssettings.LOG_DIR_PATH):
|
|
19
|
+
os.makedirs(log_dir, exist_ok=True)
|
|
20
|
+
self.log_dir = log_dir
|
|
21
|
+
|
|
22
|
+
# Generate or get log file path
|
|
23
|
+
today = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
24
|
+
self.log_path = os.path.join(log_dir, f"logs_{today}.log")
|
|
25
|
+
|
|
26
|
+
if self.LOG_RETENTION_DAYS > 0:
|
|
27
|
+
# Clean up old logs
|
|
28
|
+
self.cleanup_old_logs()
|
|
29
|
+
|
|
30
|
+
def log(self, level, message):
|
|
31
|
+
"""Log a message with the specified level of severity"""
|
|
32
|
+
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
33
|
+
log_message = f"[{timestamp}] {level.upper()} {message}"
|
|
34
|
+
if mcssettings.DEBUG:
|
|
35
|
+
print(log_message)
|
|
36
|
+
|
|
37
|
+
with open(self.log_path, "a", encoding="utf-8") as log_file:
|
|
38
|
+
log_file.write(log_message + "\n")
|
|
39
|
+
|
|
40
|
+
def cleanup_old_logs(self):
|
|
41
|
+
"""Deletes log files older than LOG_RETENTION_DAYS."""
|
|
42
|
+
cutoff_date = datetime.datetime.now() - datetime.timedelta(
|
|
43
|
+
days=self.LOG_RETENTION_DAYS
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# Find all log files matching the pattern
|
|
47
|
+
log_files = glob.glob(os.path.join(self.log_dir, "mcsc_*.log"))
|
|
48
|
+
|
|
49
|
+
for log_file in log_files:
|
|
50
|
+
# Extract the date from the filename
|
|
51
|
+
try:
|
|
52
|
+
filename = os.path.basename(log_file)
|
|
53
|
+
file_date_str = filename.replace("mcsc_", "").replace(".log", "")
|
|
54
|
+
file_date = datetime.datetime.strptime(file_date_str, "%Y-%m-%d")
|
|
55
|
+
|
|
56
|
+
# Delete files older than the retention period
|
|
57
|
+
if file_date < cutoff_date:
|
|
58
|
+
os.remove(log_file)
|
|
59
|
+
print(f"Deleted old log file: {log_file}")
|
|
60
|
+
|
|
61
|
+
except ValueError:
|
|
62
|
+
pass # Ignore files that don't match the date format
|
|
63
|
+
|
|
64
|
+
def info(self, message: str):
|
|
65
|
+
"""
|
|
66
|
+
Log an informational message.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
message (str): The message to log.
|
|
70
|
+
"""
|
|
71
|
+
self.log("INFO", message)
|
|
72
|
+
|
|
73
|
+
def debug(self, message: str):
|
|
74
|
+
"""
|
|
75
|
+
Log a debug message.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
message (str): The message to log.
|
|
79
|
+
"""
|
|
80
|
+
self.log("DEBUG", message)
|
|
81
|
+
|
|
82
|
+
def warning(self, message: str):
|
|
83
|
+
"""
|
|
84
|
+
Log a warning message.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
message (str): The message to log.
|
|
88
|
+
"""
|
|
89
|
+
self.log("WARNING", message)
|
|
90
|
+
|
|
91
|
+
def error(self, message: str):
|
|
92
|
+
"""
|
|
93
|
+
Log an error message.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
message (str): The message to log.
|
|
97
|
+
"""
|
|
98
|
+
self.log("ERROR", message)
|
|
99
|
+
|
|
100
|
+
def critical(self, message: str):
|
|
101
|
+
"""
|
|
102
|
+
Log a critical message.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
message (str): The message to log.
|
|
106
|
+
"""
|
|
107
|
+
self.log("CRITICAL", message)
|