diff --git a/generic_executor.py b/generic_executor.py index 8b79e26..030f30c 100644 --- a/generic_executor.py +++ b/generic_executor.py @@ -107,6 +107,11 @@ def server_create(user: UserRecord, name: str, version: str, framework: str = "p def server_delete(name: str, user: UserRecord) -> tuple[HTTPStatus, str or None]: user_id = user.uid + try: + port: int = firebase_manager.get_server_port(user_id) + mc_manager.stop_server_forcefully(port) + except Exception as e: + file_manager.log_error(type(e).__name__, str(e)+f" error when stopping server {name}") server_path: str = f"users/{user_id}/{name}" try: firebase_manager.delete_server(user_id, name) diff --git a/server_mc_manager.py b/server_mc_manager.py index 2408030..c217436 100644 --- a/server_mc_manager.py +++ b/server_mc_manager.py @@ -18,7 +18,7 @@ class MinecraftServerManager: if port in self.servers: return None - command = f"{java_executable} -Xmx{memory_size} -Xms{memory_size} -jar {jar_file} > /dev/null" + command = f"{java_executable} -Xmx{memory_size} -Xms{memory_size} -jar {jar_file} --nogui > /dev/null" process = subprocess.Popen(shlex.split(command), cwd=server_directory, stdin=subprocess.PIPE) self.servers_count = len(self.servers) + 1 @@ -45,12 +45,12 @@ class MinecraftServerManager: del self.servers[port] return True - def stop_server_forcefully(self, server_id) -> bool: - if server_id not in self.servers: + def stop_server_forcefully(self, port) -> bool: + if port not in self.servers: return False - process = self.servers[server_id]['process'] + process = self.servers[port]['process'] process.terminate() - del self.servers[server_id] + del self.servers[port] return True def get_servers(self):