33 lines
784 B
Plaintext
Executable File
33 lines
784 B
Plaintext
Executable File
#!/usr/bin/with-contenv /bin/sh
|
|
|
|
set -eu
|
|
|
|
PG_HOME=/var/lib/postgresql/data
|
|
|
|
if [ -f $PG_HOME/package-version ]; then
|
|
[ ! -f /backup/postgresql/dump ] || [ "$(cat $PG_HOME/package-version)" == "$POSTGRES_VERSION" ] && exit
|
|
rm ${PG_HOME}.old || true
|
|
mv $PG_HOME ${PG_HOME}.old
|
|
fi
|
|
|
|
as_pg() {
|
|
s6-setuidgid postgres "$@"
|
|
}
|
|
|
|
as_pg initdb -D $PG_HOME
|
|
as_pg pg_ctl -D $PG_HOME -w start
|
|
|
|
if [ -f /backup/postgresql/dump ]; then
|
|
as_pg psql -d postgres -f /backup/postgresql/dump
|
|
else
|
|
as_pg createuser icinga
|
|
as_pg createdb -O icinga -E UTF8 icinga
|
|
as_pg psql -d icinga < /usr/share/icinga2-ido-pgsql/schema/pgsql.sql
|
|
|
|
as_pg createuser grafana
|
|
as_pg createdb -O grafana -E UTF8 grafana
|
|
fi
|
|
|
|
echo "$POSTGRES_VERSION" > $PG_HOME/package-version
|
|
as_pg pg_ctl -D $PG_HOME -w stop
|