forked from ome/omero-server-docker
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·105 lines (88 loc) · 2.89 KB
/
run.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
set -eu
TARGET=${1:-master}
OMERO_SERVER=/opt/omero/server/OMERO.server
omero=$OMERO_SERVER/bin/omero
cd /opt/omero/server
if [ "$TARGET" = bash ]; then
echo "Entering a shell"
exec bash -l
elif [ "$TARGET" = master ]; then
# Remaining args are the servers to run, default (no args) is to run all
# on master
if [ $# -gt 1 ]; then
shift
ARGS="$@"
else
ARGS=
fi
./process_defaultxml.py OMERO.server/etc/templates/grid/default.xml.orig \
$ARGS > OMERO.server/etc/templates/grid/default.xml
DBHOST=${DBHOST:-}
if [ -z "$DBHOST" ]; then
DBHOST=db
fi
DBUSER=${DBUSER:-omero}
DBNAME=${DBNAME:-omero}
DBPASS=${DBPASS:-omero}
ROOTPASS=${ROOTPASS:-omero}
MASTER_IP=$(hostname -i)
export PGPASSWORD="$DBPASS"
i=0
while ! psql -h $DBHOST -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 -U$DBUSER $DBNAME -c \
"select * from dbpatch" 2> /dev/null && {
echo "Upgrading database"
DBCMD=upgrade
} || {
echo "Initialising database"
DBCMD=init
}
/opt/omero/omego/bin/omego db $DBCMD \
--dbhost "$DBHOST" --dbuser "$DBUSER" --dbname "$DBNAME" \
--dbpass "$DBPASS" --rootpass "$ROOTPASS" --serverdir=OMERO.server
$omero config set omero.db.host "$DBHOST"
$omero config set omero.db.user "$DBUSER"
$omero config set omero.db.name "$DBNAME"
$omero config set omero.db.pass "$DBPASS"
$omero config set omero.master.host "$MASTER_IP"
if stat -t /config/* > /dev/null 2>&1; then
for f in /config/*; do
echo "Loading $f"
$omero load "$f"
done
fi
echo "Starting $TARGET"
exec $omero admin start --foreground
else
MASTER_ADDR=${MASTER_ADDR:-}
if [ -z "$MASTER_ADDR" ]; then
MASTER_ADDR=master
fi
SLAVE_ADDR=$(hostname -i)
$omero config set omero.master.host "$MASTER_ADDR"
if stat -t /config/* > /dev/null 2>&1; then
for f in /config/*; do
echo "Loading $f"
$omero load "$f"
done
fi
echo "Master addr: $MASTER_ADDR Slave addr: $SLAVE_ADDR"
sed -e "s/@omero.slave.host@/$SLAVE_ADDR/" -e "s/@slave.name@/$TARGET/" \
slave.cfg > OMERO.server/etc/$TARGET.cfg
grep '^Ice.Default.Router=' OMERO.server/etc/ice.config || \
echo Ice.Default.Router= >> OMERO.server/etc/ice.config
sed -i -r "s|^(Ice.Default.Router=).*|\1OMERO.Glacier2/router:tcp -p 4063 -h $MASTER_ADDR|" \
OMERO.server/etc/ice.config
echo "Starting node $TARGET"
exec $omero node $TARGET start --foreground
fi