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.

run.sh 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #! /usr/bin/env bash
  2. if [ "${POSTGRES_SLAVE_INDEX}" == "" ]
  3. then
  4. echo "No POSTGRES_SLAVE_INDEX defined. Exiting."
  5. exit 0
  6. fi
  7. set_var_value()
  8. {
  9. var_name="${1}"_"${POSTGRES_SLAVE_INDEX}"
  10. export "${1}"="${!var_name}"
  11. }
  12. set_var_value POSTGRES_SLAVE_ENABLED
  13. if [ "${POSTGRES_SLAVE_ENABLED}" -ne 1 ]
  14. then
  15. echo "Slave is disabled. Exiting."
  16. exit 0
  17. fi
  18. set_var_value POSTGRES_SLAVE_REP_HOST
  19. set_var_value POSTGRES_SLAVE_REP_USER
  20. set_var_value POSTGRES_SLAVE_REP_PASSWORD
  21. set_var_value POSTGRES_SLAVE_REP_PORT
  22. . /common.sh
  23. replace_files
  24. replace_var /var/lib/postgresql/data/recovery.conf POSTGRES_SLAVE_REP_HOST
  25. replace_var /var/lib/postgresql/data/recovery.conf POSTGRES_SLAVE_REP_USER
  26. replace_var /var/lib/postgresql/data/recovery.conf POSTGRES_SLAVE_REP_PASSWORD
  27. replace_var /var/lib/postgresql/data/recovery.conf POSTGRES_SLAVE_REP_PORT
  28. rm -rf /tmp/*
  29. mv /var/lib/postgresql/data/*.conf /tmp
  30. rm -rf /var/lib/postgresql/data/*
  31. PGPASSWORD="${POSTGRES_SLAVE_REP_PASSWORD}" pg_basebackup -h "${POSTGRES_SLAVE_REP_HOST}" -p "${POSTGRES_SLAVE_REP_PORT}" -D /var/lib/postgresql/data -U "${POSTGRES_SLAVE_REP_USER}" -v
  32. mv /tmp/*.conf /var/lib/postgresql/data/
  33. docker-entrypoint.sh postgres