#!/bin/bash set -e # ── Initialise PostgreSQL data directory on first run ───────────────────────── if [ ! -f /var/lib/postgresql/data/PG_VERSION ]; then echo "Initialising PostgreSQL data directory..." su -c "/usr/lib/postgresql/16/bin/initdb -D /var/lib/postgresql/data --encoding=UTF8 --locale=C" postgres # Start postgres temporarily to create the app database and user su -c "/usr/lib/postgresql/16/bin/pg_ctl -D /var/lib/postgresql/data -w start" postgres su -c "psql -c \"CREATE USER condado WITH PASSWORD 'condado';\"" postgres su -c "psql -c \"CREATE DATABASE condado OWNER condado;\"" postgres su -c "/usr/lib/postgresql/16/bin/pg_ctl -D /var/lib/postgresql/data -w stop" postgres echo "PostgreSQL initialised." fi # ── Ensure supervisor log directory exists ──────────────────────────────────── mkdir -p /var/log/supervisor # ── Start all services via supervisord ─────────────────────────────────────── exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf