wm/db

50 lines
966 B
Plaintext
Raw Permalink Normal View History

2021-05-19 22:57:45 +03:00
#!/bin/bash
set -euo pipefail
name=wm-mj
_psql() {
env \
PGPASSWORD=osm \
PGHOST=127.0.0.1 \
PGUSER=osm \
PGDATABASE=osm \
psql "$@"
}
_wait_for_postgres() {
>&2 echo -n "Waiting for postgres"
for _ in $(seq 240); do
if _psql -qc '\q' 2>/dev/null; then
>&2 echo " up"
exit 0
fi
>&2 echo -n .
sleep 1
done
>&2 echo " down"
exit 1
}
case ${1:-} in
start)
2021-05-19 22:57:46 +03:00
_psql -qc '\q' 2>/dev/null && exit 0
2021-05-19 22:57:45 +03:00
docker run -d --rm \
2021-05-19 22:57:50 +03:00
--net=host \
2021-05-19 22:57:45 +03:00
-e POSTGRES_DBNAME=osm \
-e POSTGRES_USER=osm \
-e POSTGRES_PASSWORD=osm \
--name "$name" \
2021-05-19 22:57:46 +03:00
postgis/postgis:13-3.1-alpine \
2021-05-19 22:57:50 +03:00
-c log_statement=all \
-c listen_addresses=127.0.0.1
2021-05-19 22:57:45 +03:00
_wait_for_postgres
;;
stop)
docker stop "$name"
;;
*)
2021-05-19 22:57:45 +03:00
_psql "$@"
2021-05-19 22:57:45 +03:00
;;
esac