Improve permissions handling in local-up script: only change log and Loki data directory permissions if necessary

This commit is contained in:
Ross
2025-12-22 10:06:54 +00:00
parent c071f38920
commit 54e1cf4ce0
+25 -2
View File
@@ -53,14 +53,37 @@ mkdir -p "$REPO_ROOT/docker/loki-data/index" \
"$REPO_ROOT/logs"
# Set permissive perms for logs so nginx/promtail can use it in development.
chmod -R 0777 "$REPO_ROOT/logs" || true
# Only change permissions if the directory doesn't already have the desired mode.
if [ -d "$REPO_ROOT/logs" ]; then
_mode=$(stat -c %a "$REPO_ROOT/logs" 2>/dev/null || true)
if [ -z "$_mode" ]; then
chmod -R 0777 "$REPO_ROOT/logs" || true
else
if [ "$_mode" != "777" ]; then
chmod -R 0777 "$REPO_ROOT/logs" || true
fi
fi
fi
# Ensure loki data directories exist and have reasonable perms. The Loki
# container runs as numeric UID 10001; if possible try to chown the folders to
# that UID so Loki can write to them. If sudo is available the script will
# attempt it (you may be prompted). If it fails we'll continue and leave a
# message for manual intervention.
chmod -R 0755 "$REPO_ROOT/docker/loki-data" "$REPO_ROOT/docker/loki-wal" || true
# Ensure loki data directories exist and have reasonable perms. Only chmod
# each path if its current mode differs from the desired one.
for _p in "$REPO_ROOT/docker/loki-data" "$REPO_ROOT/docker/loki-wal"; do
if [ -d "$_p" ]; then
_mode=$(stat -c %a "$_p" 2>/dev/null || true)
if [ -z "$_mode" ]; then
chmod -R 0755 "$_p" || true
else
if [ "$_mode" != "755" ]; then
chmod -R 0755 "$_p" || true
fi
fi
fi
done
if [ "$(id -u)" -eq 0 ]; then
chown -R 10001:10001 "$REPO_ROOT/docker/loki-data" "$REPO_ROOT/docker/loki-wal" || true
else