Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

updated entrypoint script to wait for postgres

Jonas Winkler3afee66aaa1a
diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh
index c6e0d1cab..dfa7cfc65 100644
--- a/docker/docker-entrypoint.sh
+++ b/docker/docker-entrypoint.sh
@@ -15,8 +15,42 @@ map_uidgid() {
fi
}
+
+wait_for_postgres() {
+ attempt_num=1
+ max_attempts=5
+
+ echo "Waiting for PostgreSQL to start..."
+
+ host="${PAPERLESS_DBHOST}"
+
+ while !</dev/tcp/$host/5432 ;
+ do
+
+ if [ $attempt_num -eq $max_attempts ]
+ then
+ echo "Unable to connect to database."
+ exit 1
+ else
+ echo "Attempt $attempt_num failed! Trying again in 5 seconds..."
+
+ fi
+
+ attempt_num=$(expr "$attempt_num" + 1)
+ sleep 5
+ done
+
+
+}
+
+
migrations() {
+ if [[ -n "${PAPERLESS_DBHOST}" ]]
+ then
+ wait_for_postgres
+ fi
+
(
# flock is in place to prevent multiple containers from doing migrations
# simultaneously. This also ensures that the db is ready when the command