mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-05-28 06:20:14 +00:00
Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/6ba2c0de-f503-4989-9dea-4bc64a51e4f9 Co-authored-by: szaimen <42591237+szaimen@users.noreply.github.com>
67 lines
2.4 KiB
Bash
67 lines
2.4 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
# Validate required environment variables
|
|
if [ -z "$BASE_URL" ]; then
|
|
echo "BASE_URL must be provided. Exiting!"
|
|
exit 1
|
|
fi
|
|
|
|
export TZ="${TZ:-Etc/UTC}"
|
|
|
|
# Clear the cache volume when the image has been updated.
|
|
# /etc/windmill-image-build-epoch is written at image build time.
|
|
# A copy is stored in the cache volume after first start.
|
|
# If the two differ the image was updated and any stale cached artefacts
|
|
# (uv tools, worker dirs) should be removed so Windmill starts clean.
|
|
IMAGE_EPOCH_FILE="/etc/windmill-image-build-epoch"
|
|
CACHE_EPOCH_FILE="/tmp/windmill/cache/.image-build-epoch"
|
|
if [ -f "$IMAGE_EPOCH_FILE" ]; then
|
|
IMAGE_EPOCH="$(cat "$IMAGE_EPOCH_FILE")"
|
|
if [ -f "$CACHE_EPOCH_FILE" ]; then
|
|
CACHE_EPOCH="$(cat "$CACHE_EPOCH_FILE")"
|
|
if [ "$IMAGE_EPOCH" != "$CACHE_EPOCH" ]; then
|
|
echo "Windmill image updated (was $CACHE_EPOCH, now $IMAGE_EPOCH). Clearing cache..."
|
|
find /tmp/windmill/cache -mindepth 1 -maxdepth 1 ! -name '.image-build-epoch' -exec rm -rf {} +
|
|
fi
|
|
fi
|
|
echo "$IMAGE_EPOCH" > "$CACHE_EPOCH_FILE"
|
|
fi
|
|
|
|
PGDATA="/var/lib/postgresql/data"
|
|
|
|
# Initialize PostgreSQL data directory on first run.
|
|
# No su/chown needed — we already own PGDATA (the windmill user owns the volume).
|
|
if [ -z "$(ls -A "$PGDATA" 2>/dev/null)" ]; then
|
|
echo "Initializing PostgreSQL database for Windmill..."
|
|
|
|
initdb -D "$PGDATA" \
|
|
--username=windmill \
|
|
--auth-local=trust \
|
|
--auth-host=trust \
|
|
--no-instructions
|
|
|
|
# Allow local connections without a password; listen only on localhost
|
|
cat > "$PGDATA/pg_hba.conf" << 'EOF'
|
|
# TYPE DATABASE USER ADDRESS METHOD
|
|
local all all trust
|
|
host all all 127.0.0.1/32 trust
|
|
host all all ::1/128 trust
|
|
EOF
|
|
|
|
cat >> "$PGDATA/postgresql.conf" << 'EOF'
|
|
listen_addresses = 'localhost'
|
|
EOF
|
|
|
|
# Start PostgreSQL temporarily to create the windmill database, then stop it.
|
|
# supervisord will restart it properly afterward.
|
|
pg_ctl -D "$PGDATA" start -w -o "-k /var/run/postgresql"
|
|
psql -h /var/run/postgresql -U windmill postgres \
|
|
-c "CREATE DATABASE windmill OWNER windmill;"
|
|
pg_ctl -D "$PGDATA" stop -w
|
|
|
|
echo "PostgreSQL initialization complete."
|
|
fi
|
|
|
|
exec supervisord -c /supervisord.conf
|