-
Notifications
You must be signed in to change notification settings - Fork 26
/
60-database.sh
executable file
·46 lines (40 loc) · 1.3 KB
/
60-database.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# 50-config.py or equivalent must be run first to set all omero.db.*
# omero.db.host may require special handling since the default is
# to use `--link postgres:db`
set -eu
omero=/opt/omero/server/venv3/bin/omero
omego=/opt/omero/server/venv3/bin/omego
cd /opt/omero/server
CONFIG_omero_db_host=${CONFIG_omero_db_host:-}
if [ -n "$CONFIG_omero_db_host" ]; then
DBHOST="$CONFIG_omero_db_host"
else
DBHOST=db
$omero config set omero.db.host "$DBHOST"
fi
DBUSER="${CONFIG_omero_db_user:-omero}"
DBNAME="${CONFIG_omero_db_name:-omero}"
DBPASS="${CONFIG_omero_db_pass:-omero}"
DBPORT="${CONFIG_omero_db_port:-5432}"
ROOTPASS="${ROOTPASS:-omero}"
export PGPASSWORD="$DBPASS"
i=0
while ! psql -h "$DBHOST" -p "$DBPORT" -U "$DBUSER" "$DBNAME" >/dev/null 2>&1 < /dev/null; do
i=$(($i+1))
if [ $i -ge 50 ]; then
echo "$(date) - postgres:5432 still not reachable, giving up"
exit 1
fi
echo "$(date) - waiting for postgres:5432..."
sleep 1
done
echo "postgres connection established"
psql -w -h "$DBHOST" -p "$DBPORT" -U "$DBUSER" "$DBNAME" -c \
"select * from dbpatch" 2> /dev/null && {
echo "Upgrading database"
$omego db upgrade --serverdir=OMERO.server
} || {
echo "Initialising database"
$omego db init --rootpass "$ROOTPASS" --serverdir=OMERO.server
}