From 4a15a2331efc4745ca7fbe1dfc7e5a2a9f6bf86b Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 10 Jun 2022 18:29:47 -0400 Subject: [PATCH 1/4] Fix error when stats job does not exist on kill --- app/classes/shared/server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index f31dc7c8..7b86ffd6 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -14,6 +14,7 @@ import tempfile # TZLocal is set as a hidden import on win pipeline from tzlocal import get_localzone from apscheduler.schedulers.background import BackgroundScheduler +from apscheduler.jobstores.base import JobLookupError from app.classes.minecraft.stats import Stats from app.classes.minecraft.mc_ping import ping, ping_bedrock @@ -687,7 +688,11 @@ class ServerInstance: proc.kill() # kill the main process we are after logger.info("Sending SIGKILL to parent") - self.server_scheduler.remove_job("stats_" + str(self.server_id)) + try: + self.server_scheduler.remove_job("stats_" + str(self.server_id)) + except JobLookupError as e: + logger.error(f"Could not remove job with id stats_{self.server_id} due"+ + f" to error: {e}") self.process.kill() def get_start_time(self): From 41cf247c5a0ad1863289e24980f8d8734bfc6306 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 10 Jun 2022 18:31:48 -0400 Subject: [PATCH 2/4] Appease black --- app/classes/shared/server.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 7b86ffd6..7ff2f243 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -691,8 +691,10 @@ class ServerInstance: try: self.server_scheduler.remove_job("stats_" + str(self.server_id)) except JobLookupError as e: - logger.error(f"Could not remove job with id stats_{self.server_id} due"+ - f" to error: {e}") + logger.error( + f"Could not remove job with id stats_{self.server_id} due" + + f" to error: {e}" + ) self.process.kill() def get_start_time(self): From c924663ab3964e772f6114f42753c3f3b02e150a Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 10 Jun 2022 19:04:34 -0400 Subject: [PATCH 3/4] Fix stack on server stop --- app/classes/shared/server.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 7ff2f243..24daaceb 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -593,9 +593,14 @@ class ServerInstance: self.cleanup_server_object() server_users = PermissionsServers.get_server_user_list(self.server_id) - # remove the stats polling job since server is stopped - self.server_scheduler.remove_job("stats_" + str(self.server_id)) - + try: + # remove the stats polling job since server is stopped + self.server_scheduler.remove_job("stats_" + str(self.server_id)) + except JobLookupError as e: + logger.error( + f"Could not remove job with id stats_{self.server_id} due" + + f" to error: {e}" + ) self.record_server_stats() for user in server_users: From 47da0ab1aa3e770dea88a07d0be61ca34dcd77dd Mon Sep 17 00:00:00 2001 From: Iain Powrie Date: Fri, 10 Jun 2022 23:30:33 +0000 Subject: [PATCH 4/4] Wrapper optimisation --- docker_launcher.sh | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/docker_launcher.sh b/docker_launcher.sh index 3a14a2d0..0237b75f 100644 --- a/docker_launcher.sh +++ b/docker_launcher.sh @@ -1,31 +1,44 @@ #!/bin/sh -# Check if config exists from existing installation (venv or previous docker launch) +# Check if config exists taking one from image if needed. if [ ! "$(ls -A --ignore=.gitkeep ./app/config)" ]; then - echo "Wrapper | Config not found, pulling defaults..." + echo "Wrapper | 🏗️ Config not found, pulling defaults..." mkdir ./app/config/ 2> /dev/null cp -r ./app/config_original/* ./app/config/ + + if [ $(id -u) -eq 0 ]; then + # We're running as root; + # Look for files & dirs that require group permissions to be fixed + # This will do the full /crafty dir, so will take a miniute. + echo "Wrapper | 📋 Looking for problem bind mount permissions globally..." + find . ! -group root -exec chgrp root {} \; + find . ! -perm g+rw -exec chmod g+rw {} \; + find . -type d ! -perm g+s -exec chmod g+s {} \; + fi fi if [ $(id -u) -eq 0 ]; then - # We're running as root; - # Need to ensure all dirs are owned by the root group, - # This fixes bind mounts that may have incorrect perms. + # We're running as root - # Look for files & dirs that require group permissions to be fixed - echo "Wrapper | Looking for problem bind mount permissions" - find . ! -group root -exec chgrp root {} \; - find . ! -perm g+rw -exec chmod g+rw {} \; - find . -type d ! -perm g+s -exec chmod g+s {} \; + # If we find files in import directory, we need to ensure all dirs are owned by the root group, + # This fixes bind mounts that may have incorrect perms. + if [ ! "$(ls -A --ignore=.gitkeep ./app/import)" ]; then + echo "Wrapper | 📋 Files present in import, checking/fixing permissions..." + echo "Wrapper | ⏳ Please be paitent for larger servers..." + find . ! -group root -exec chgrp root {} \; + find . ! -perm g+rw -exec chmod g+rw {} \; + find . -type d ! -perm g+s -exec chmod g+s {} \; + echo "Wrapper | ✅ Permissions Fixed! (This will happen every boot until /import is empty!)" + fi # Switch user, activate our prepared venv and lauch crafty args="$@" - echo "Wrapper | Launching crafty with [$args]" + echo "Wrapper | 🚀 Launching crafty with [$args]" exec sudo -u crafty bash -c "source ./.venv/bin/activate && exec python3 main.py $args" else # Activate our prepared venv - echo "Wrapper | Non-root host detected, using normal exec" + echo "Wrapper | 🚀 Non-root host detected, using normal exec" . ./.venv/bin/activate # Use exec as our perms are already correct # This is likely if using Kubernetes/OpenShift etc