Browse Source

fix: [peertube] peertube would fail if postgres is not ready at start

framadate
Valentin Lab 6 years ago
parent
commit
7c86d235a9
  1. 7
      peertube/build/Dockerfile
  2. 30
      peertube/build/src/entrypoint.sh
  3. 17
      peertube/hooks/postgres_database-relation-joined

7
peertube/build/Dockerfile

@ -94,7 +94,12 @@ RUN apk add nodejs-npm
## runtime deps ## runtime deps
RUN apk add openssl RUN apk add openssl
## to check if postgres is fine BEFORE running the app
RUN apk add postgresql-client
COPY src/ .
USER peertube USER peertube
WORKDIR /opt/apps/peertube WORKDIR /opt/apps/peertube
CMD ["npm", "start"]
CMD ["/entrypoint.sh"]

30
peertube/build/src/entrypoint.sh

@ -0,0 +1,30 @@
#!/bin/sh
timeout=120
start="$(date +%s)"
while true; do
if err=$(echo "SELECT 1;" | psql 2>&1 >/dev/null); then
break
fi
now=$(date +%s)
if ! [ "$err" = "psql: FATAL: the database system is starting up" ]; then
echo "postgres connection error:" \
"Could not connect to '$PGHOST'. (will retry)"
if [ "$err" ]; then
echo " Error:" >&2
printf "%s\n" "$err" | sed -r "s/^/ ! /g" >&2
fi
else
echo "Got 'database system is starting up' error... waiting before launching npm start" >&2
fi
elapsed=$((now - start))
if [ "$elapsed" -gt "$timeout" ]; then
echo "postgre connection error:"\
"Could not connect to db on '$PGHOST'" \
"container's IP."
exit 1
fi
sleep 0.5
done
exec npm start

17
peertube/hooks/postgres_database-relation-joined

@ -22,4 +22,21 @@ database:
EOF EOF
## XXXvlab: needed only for psql access to check if database is ready
## before launching the app.
uid=$(docker_get_uid "$SERVICE_NAME" peertube) || exit 1
chown "$uid" "$SERVICE_CONFIGSTORE/root/.pgpass" || exit 1
config-add "
services:
$MASTER_BASE_SERVICE_NAME:
environment:
PGUSER: $USER
PGHOST: $TARGET_SERVICE_NAME
PGDATABASE: $DBNAME
volumes:
- $SERVICE_CONFIGSTORE/root/.pgpass:/var/lib/peertube/.pgpass
"
info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access." info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access."
Loading…
Cancel
Save