diff --git a/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml b/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml index b3cc8ea..752a97e 100644 --- a/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml +++ b/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml @@ -18,6 +18,13 @@ services: volumes: - "<%= postgres_datapath %>:/var/lib/postgresql/data" - "<%= logs_datapath %>:/cnlogs" + - container_monitor:/container_monitor + healthcheck: + test: sh -c 'psql -U cyphernode -c "select 1;" && touch /container_monitor/postgres_ready && chown $USER /container_monitor/postgres_ready || rm -f /container_monitor/postgres_ready' + interval: 30s + timeout: 10s + retries: 10 + stop_grace_period: 30s networks: - cyphernodenet <% if ( docker_mode === 'swarm' ) { %> diff --git a/proxy_docker/app/data/sqlmigrate20211105_0.7.0-0.8.0.sh b/proxy_docker/app/data/sqlmigrate20211105_0.7.0-0.8.0.sh index b9378e1..d615c0e 100644 --- a/proxy_docker/app/data/sqlmigrate20211105_0.7.0-0.8.0.sh +++ b/proxy_docker/app/data/sqlmigrate20211105_0.7.0-0.8.0.sh @@ -2,10 +2,11 @@ . ./trace.sh -trace "[sqlmigrate20211105_0.7.0-0.8.0.sh] Waiting for postgres to be ready..." -while true ; do psql -h postgres -U cyphernode -c "select 1;" ; [ "$?" -eq "0" ] && break ; sleep 10; done +trace "[sqlmigrate20211105_0.7.0-0.8.0.sh] Waiting for PostgreSQL to be ready..." +while [ ! -f "/container_monitor/postgres_ready" ]; do echo "PostgreSQL not ready" ; sleep 10 ; done +trace "[sqlmigrate20211105_0.7.0-0.8.0.sh] PostgreSQL ready!" -trace "[sqlmigrate20211105_0.7.0-0.8.0.sh] Checking if postgres is setup..." +trace "[sqlmigrate20211105_0.7.0-0.8.0.sh] Checking if postgres is set up..." psql -h postgres -U cyphernode -c "\d" | grep "cyphernode_props" > /dev/null if [ "$?" -eq "1" ]; then # if cyphernode_props table doesn't exist, it's probably because database hasn't been setup yet diff --git a/proxy_docker/app/script/startproxy.sh b/proxy_docker/app/script/startproxy.sh index 21302a0..6f855fe 100644 --- a/proxy_docker/app/script/startproxy.sh +++ b/proxy_docker/app/script/startproxy.sh @@ -37,6 +37,10 @@ fi if [ ! -e ${DB_FILE} ]; then trace "[startproxy] DB not found, creating..." cat cyphernode.sql | sqlite3 $DB_FILE + + trace "[startproxy] Waiting for PostgreSQL to be ready..." + while [ ! -f "/container_monitor/postgres_ready" ]; do echo "PostgreSQL not ready" ; sleep 10 ; done + trace "[startproxy] PostgreSQL ready!" psql -h postgres -f cyphernode.postgresql -U cyphernode returncode=$? trace_rc ${returncode}