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.

45 lines
1.5 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. . lib/common
  12. set -e
  13. if ! [ -f "$HOST_DB_PASSFILE" ]; then
  14. POSTGRES_ROOT_PASSWORD="$(gen_password)"
  15. ddb < <(echo "ALTER USER postgres WITH ENCRYPTED password '$POSTGRES_ROOT_PASSWORD'")
  16. cat <<EOF > "$HOST_DB_PASSFILE"
  17. *:*:*:postgres:$POSTGRES_ROOT_PASSWORD
  18. EOF
  19. chmod 600 "$HOST_DB_PASSFILE"
  20. info "New root password for postgres. "
  21. fi
  22. if ! egrep "^host all all (0.0.0.0/0|all) md5\$" "$PG_HBA" >/dev/null 2>&1; then
  23. if egrep "^host all all (0.0.0.0/0|all) trust\$" "$PG_HBA" >/dev/null 2>&1; then
  24. sed -ri 's%^host all all (0\.0\.0\.0/0|all) trust$%host all all \1 md5%g' \
  25. "$PG_HBA"
  26. if is_db_locked; then
  27. ensure_db_docker_running
  28. docker restart "$container_id"
  29. info "Restarted container $container_id"
  30. fi
  31. info "Accepting connection from outside."
  32. else
  33. die "Can't ensure connection from outside. Please update the charm init script."
  34. fi
  35. fi