From 76d4fd1bbc60930a5196d22d94553a0da983b22b Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Tue, 6 Sep 2016 21:36:54 -0500 Subject: [PATCH] [mc] Check writability of /data before chown'ing it For #104 --- minecraft-server/Dockerfile | 3 ++- minecraft-server/start.sh | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/minecraft-server/Dockerfile b/minecraft-server/Dockerfile index 4e21467f..41d23067 100644 --- a/minecraft-server/Dockerfile +++ b/minecraft-server/Dockerfile @@ -19,7 +19,8 @@ RUN useradd -s /bin/false --uid 1000 minecraft \ && mkdir /config \ && mkdir /mods \ && mkdir /plugins \ - && chown minecraft:minecraft /data /config /mods /plugins + && mkdir /home/minecraft \ + && chown minecraft:minecraft /data /config /mods /plugins /home/minecraft EXPOSE 25565 25575 diff --git a/minecraft-server/start.sh b/minecraft-server/start.sh index 06efca94..65ba4275 100755 --- a/minecraft-server/start.sh +++ b/minecraft-server/start.sh @@ -4,16 +4,17 @@ set -e usermod --uid $UID minecraft groupmod --gid $GID minecraft -chown -R minecraft:minecraft /data /start-minecraft /home/minecraft -chmod -R g+wX /data /start-minecraft +fix_ownership() { + dir=$1 + if ! sudo -u minecraft test -w $dir; then + echo "Correcting writability of $dir ..." + chown -R minecraft:minecraft $dir + chmod -R u+w $dir + fi +} -while lsof -- /start-minecraft; do - echo -n "." - sleep 1 -done - -mkdir -p /home/minecraft -chown minecraft: /home/minecraft +fix_ownership /data +fix_ownership /home/minecraft echo "Switching to user 'minecraft'" exec sudo -E -u minecraft /start-minecraft "$@"