mirror of
https://github.com/opus-tango/minecraft-server-discord-bot.git
synced 2026-03-20 03:55:20 +00:00
add stop polling on server shutdown
This commit is contained in:
14
bot.py
14
bot.py
@@ -210,11 +210,15 @@ async def _stop_server_internal(ctx, servername, method):
|
|||||||
await ctx.send(f"Failed to send stop command to screen: {e}")
|
await ctx.send(f"Failed to send stop command to screen: {e}")
|
||||||
# Even if command fails, attempt cleanup
|
# Even if command fails, attempt cleanup
|
||||||
|
|
||||||
# Give the server some time to shut down gracefully
|
# Check if the server is still running every second until the server stops or the timeout is reached
|
||||||
if method == "stop":
|
for i in range(30):
|
||||||
await asyncio.sleep(15) # Minecraft servers can take a while to save and stop
|
check_screen_cmd = f"screen -ls | grep {servername}"
|
||||||
else: # forcestop
|
process = subprocess.Popen(check_screen_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
await asyncio.sleep(5) # Give it a few seconds for Ctrl+C to register
|
stdout, stderr = process.communicate()
|
||||||
|
if not stdout:
|
||||||
|
break
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
# --- Cleanup ---
|
# --- Cleanup ---
|
||||||
if active_server_pipe_task:
|
if active_server_pipe_task:
|
||||||
|
|||||||
Reference in New Issue
Block a user