Wait until database is ready

This commit is contained in:
Yi EungJun 2015-12-09 17:17:25 +09:00
parent aa1b246388
commit b4ad7f2119
3 changed files with 22 additions and 4 deletions

View File

@ -35,7 +35,7 @@ Remove `volumes` directory
## Known Issues
* Do not modify the Listen Address in Service Settings.
* Sometimes 'app' container fails to start because of "connection refused" to
* Rarely 'app' container fails to start because of "connection refused" to
database. Workaround: Restart the container.
* Sometimes database connection is misconfigured. Workaround: Delete
`volumes/app/mattermost/config/config.json` and restart the 'app' container.

View File

@ -1,6 +1,6 @@
FROM ubuntu:14.04
RUN apt-get update && apt-get -y upgrade && apt-get -y install wget
RUN apt-get update && apt-get -y upgrade && apt-get -y install wget netcat
RUN mkdir -p /mattermost/data
RUN touch /etc/init/mattermost.conf

View File

@ -1,10 +1,28 @@
#!/bin/bash
echo Starting Platform
config=/mattermost/config/config.json
if [ ! -f $config ]; then
echo -ne "Configure database connection..."
if [ ! -f $config ]
then
cp /config.template.json $config
sed -Ei "s/PG_ADDR/$PG_PORT_5432_TCP_ADDR/" $config
sed -Ei "s/PG_PORT/$PG_PORT_5432_TCP_PORT/" $config
echo OK
else
echo SKIP
fi
echo -n "Wait until database is ready..."
until nc -z $PG_PORT_5432_TCP_ADDR $PG_PORT_5432_TCP_PORT
do
echo -n .
sleep 1
done
# Wait to avoid "panic: Failed to open sql connection pq: the database system is starting up"
sleep 1
echo "OK"
echo "Starting platform"
cd /mattermost/bin
./platform