Enhance local-up script to ensure Loki and nginx log directories exist with appropriate permissions

This commit is contained in:
Ross
2025-12-08 10:30:00 +00:00
parent 997b5374c2
commit 49229b0408
2 changed files with 35 additions and 0 deletions
+34
View File
@@ -41,4 +41,38 @@ if [ -f "$ENV_FILE" ]; then
done < "$ENV_FILE"
fi
# Ensure runtime directories exist for Loki and nginx logs so compose startup
# doesn't fail with permission/missing-folder errors. We create the minimal
# subfolders Loki expects and a host `logs/` for nginx/Promtail.
echo "Ensuring loki and logs folders exist under $REPO_ROOT/docker and $REPO_ROOT/logs"
mkdir -p "$REPO_ROOT/docker/loki-data/index" \
"$REPO_ROOT/docker/loki-data/cache" \
"$REPO_ROOT/docker/loki-data/chunks" \
"$REPO_ROOT/docker/loki-data/compactor" \
"$REPO_ROOT/docker/loki-wal" \
"$REPO_ROOT/logs"
# Set permissive perms for logs so nginx/promtail can use it in development.
chmod -R 0777 "$REPO_ROOT/logs" || true
# 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
if [ "$(id -u)" -eq 0 ]; then
chown -R 10001:10001 "$REPO_ROOT/docker/loki-data" "$REPO_ROOT/docker/loki-wal" || true
else
if command -v sudo >/dev/null 2>&1; then
echo "Attempting to chown loki folders to UID 10001 (may prompt for sudo password)"
sudo chown -R 10001:10001 "$REPO_ROOT/docker/loki-data" "$REPO_ROOT/docker/loki-wal" || \
echo "sudo chown failed or was cancelled; Loki may not start until these folders are owned by UID 10001"
else
echo "Note: sudo not available. Created loki folders but did not chown them."
echo "If Loki fails with permission errors, run:"
echo " sudo chown -R 10001:10001 $REPO_ROOT/docker/loki-data $REPO_ROOT/docker/loki-wal"
fi
fi
COMPOSE_ENV=$COMPOSE_ENV docker compose -f docker/docker-compose.prod.yml -f docker/docker-compose.dev.yml up --build
+1
View File
@@ -114,6 +114,7 @@
{% if collection %}
<h2>Collection: {{collection.name}}</h2>
<p class="muted"><a href="{% url 'generic:examcollection_detail' collection.pk %}">← Back to collection</a></p>
{% endif %}
<details class="help-text">