fork 0k-charms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

  1. #!/bin/bash
  2. ## Init is run on host
  3. ## For now it is run every time the script is launched, but
  4. ## it should be launched only once after build.
  5. ## Accessible variables are:
  6. ## - SERVICE_NAME Name of current service
  7. ## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
  8. ## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
  9. ## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
  10. # Please note that postgres detect on its own if its datadir needs to be populated
  11. [ -e ~/.pgpass ] && exit 0
  12. . lib/common
  13. set -e
  14. POSTGRES_ROOT_PASSWORD="$(gen_password)"
  15. ##
  16. ## Setting up access from host
  17. ##
  18. ddb < <(echo "ALTER USER postgres WITH ENCRYPTED password '$POSTGRES_ROOT_PASSWORD'")
  19. sed -ri 's%^host all all 0\.0\.0\.0/0 trust$%host all all 0.0.0.0/0 md5%g' \
  20. "$SERVICE_DATASTORE/var/lib/postgresql/data/pg_hba.conf"
  21. docker restart "$container_id"
  22. ## XXXvlab: this won't help support multiple project running on the
  23. ## same host
  24. cat <<EOF > ~/.pgpass
  25. *:*:*:postgres:$POSTGRES_ROOT_PASSWORD
  26. EOF
  27. chmod 600 ~/.pgpass
  28. ##
  29. ## pgm
  30. ##
  31. echo 'prefix_pg_local_command=" " ## otherwise, will default to sudo -u postgres ' > /root/.pgm.rc
  32. info "New root password for postgres. "