From b355898d0aeae5f5c07c9799faa5ee4f0797a316 Mon Sep 17 00:00:00 2001 From: Nayan <33187059+GShadow5@users.noreply.github.com> Date: Thu, 4 Sep 2025 00:07:22 +0000 Subject: [PATCH] add stop polling on server shutdown --- bot.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 24b27e1..8a95298 100644 --- a/bot.py +++ b/bot.py @@ -209,12 +209,16 @@ async def _stop_server_internal(ctx, servername, method): except Exception as e: await ctx.send(f"Failed to send stop command to screen: {e}") # Even if command fails, attempt cleanup + + # Check if the server is still running every second until the server stops or the timeout is reached + for i in range(30): + check_screen_cmd = f"screen -ls | grep {servername}" + process = subprocess.Popen(check_screen_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + stdout, stderr = process.communicate() + if not stdout: + break + await asyncio.sleep(1) - # Give the server some time to shut down gracefully - if method == "stop": - await asyncio.sleep(15) # Minecraft servers can take a while to save and stop - else: # forcestop - await asyncio.sleep(5) # Give it a few seconds for Ctrl+C to register # --- Cleanup --- if active_server_pipe_task: