Skip to content

Commit

Permalink
Fixed extension enabling
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed May 7, 2020
1 parent 8520200 commit 0a75ef6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
7 changes: 5 additions & 2 deletions timescaledb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ RUN apk add --no-cache \
postgresql-dev

# Create it's run directory
RUN mkdir /run/postgresql \
&& chown -R postgres:postgres /run/postgresql
RUN mkdir -p /run/postgresql \
&& chown -R postgres:postgres /run/postgresql \
&& mkdir -p /run/postgresql/extensions \
&& chown -R postgres:postgres /run/postgresql/extensions


# Copy over the tools
COPY --from=tools /go/bin/* /usr/local/bin/
Expand Down
16 changes: 8 additions & 8 deletions timescaledb/rootfs/etc/services.d/postgres/run
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if bashio::var.true "${new_install}"; then
echo "local all all md5" >> ${postgres_data}/pg_hba.conf
echo "local all all peer" >> ${postgres_data}/pg_hba.conf
# Listen on all addresses (*)
sed -r -i "s/[#]listen_addresses.=.'.*'/listen_addresses\ =\ \'\*\'/g${postgres_data}/postgresql.conf
sed -r -i "s/[#]listen_addresses.=.'.*'/listen_addresses\ \=\ \'\*\'/g" ${postgres_data}/postgresql.conf
# Set telemetry level
echo "timescaledb.telemetry_level=$(bashio::config 'timescaledb.telemetry')" >> ${postgres_data}/postgresql.conf

Expand All @@ -52,9 +52,9 @@ bashio::log.info "done"

# Wait for postgres to become availale..
sleep 3
while ! mysql -e "" 2> /dev/null; do
psql -U "postgres" postgres -c "SELECT 1;"
done
#while ! mysql -e "" 2> /dev/null; do
# psql -U "postgres" postgres -c "SELECT 1;"
#done

# Create extensions timescaledb in initial databases
psql -U "postgres" postgres -c "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;"
Expand All @@ -63,16 +63,16 @@ psql -U "postgres" template1 -c "CREATE EXTENSION IF NOT EXISTS timescaledb CASC
# Create all databases if not exist
bashio::log.info "Ensure databases exists.."
for database in $(bashio::config "databases"); do
bashio::log.info "Create database ${database}"
#psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = '${database}'" | grep -q 1 || psql -U postgres -c "CREATE DATABASE ${database}"
bashio::log.info "Create database '${database}'"
psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = '${database}'" | grep -q 1 || psql -U postgres -c "CREATE DATABASE ${database}"
done
bashio::log.info "done"

# Enable the timescale-extentions for all indicated databases
bashio::log.info "Enabling Timescale Extensions.."
for database in $(bashio::config "timescale_enabled"); do
bashio::log.info "Enabling Timescale Extension for database ${database}"
psql -U "postgres" postgres -c "CREATE EXTENSION IF NOT EXISTS ${database} CASCADE;"
bashio::log.info "Enabling Timescale Extension for database '${database}'"
psql -U "postgres" ${database} -c "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;"
done
bashio::log.info "done"

Expand Down

0 comments on commit 0a75ef6

Please sign in to comment.