| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# we first need to wait for PostgreSQL |
| 4 |
# cf. https://stackoverflow.com/a/39028690 (thanks!) |
| 5 |
|
| 6 |
RETRIES=5 |
| 7 |
|
| 8 |
until psql -c "select 1" > /dev/null 2>&1 || [ $RETRIES -eq 0 ]; do |
| 9 |
echo "Waiting for postgres server, $((RETRIES--)) remaining attempts…" |
| 10 |
sleep 1 |
| 11 |
done |
| 12 |
|
| 13 |
ori_dir=${PWD} |
| 14 |
cd /src/libervia-pubsub/db |
| 15 |
|
| 16 |
# PG should be OK, we now initialize the database. If it's already done, it will fail |
| 17 |
# with exit code 3 |
| 18 |
psql -v ON_ERROR_STOP=1 pubsub < pubsub.sql 2>/dev/null |
| 19 |
case $? in |
| 20 |
0) printf "database initialized\n" ;; |
| 21 |
3) printf "database already exists\n" ;; |
| 22 |
*) printf "can't initialize database, please check PostgreSQL container parameters\n" >&2 |
| 23 |
exit 1 |
| 24 |
;; |
| 25 |
esac |
| 26 |
|
| 27 |
cd $ori_dir |
| 28 |
|
| 29 |
exec /home/libervia/libervia_env/bin/twistd -n libervia-pubsub "$@" |