|
@ -37,6 +37,44 @@ _set_db_params() { |
|
|
|
|
|
|
|
|
export db_docker_opts="--network $docker_network -e PGHOST=$docker_ip -e PGUSER=postgres" |
|
|
export db_docker_opts="--network $docker_network -e PGHOST=$docker_ip -e PGUSER=postgres" |
|
|
export db_cmd_opts= |
|
|
export db_cmd_opts= |
|
|
|
|
|
|
|
|
|
|
|
PGHOST="$docker_ip" |
|
|
|
|
|
PGUSER="postgres" |
|
|
|
|
|
export PGHOST PGUSER |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Must setup a direct connection |
|
|
|
|
|
_set_up_connection() { |
|
|
|
|
|
|
|
|
|
|
|
if [ -e "$DB_PASSFILE" ]; then |
|
|
|
|
|
POSTGRES_ROOT_PASSWORD=$(cat "$DB_PASSFILE" | cut -f 5 -d :) |
|
|
|
|
|
else |
|
|
|
|
|
POSTGRES_ROOT_PASSWORD="$(gen_password)" |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
## |
|
|
|
|
|
## Setting up access from host |
|
|
|
|
|
## |
|
|
|
|
|
|
|
|
|
|
|
debug docker exec -i "$container_id" psql -U postgres -qAt |
|
|
|
|
|
docker exec -i "$container_id" psql -U postgres -qAt \ |
|
|
|
|
|
< <(echo "ALTER USER postgres WITH ENCRYPTED password '$POSTGRES_ROOT_PASSWORD'") || { |
|
|
|
|
|
die "direct PSQL injection failed." |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sed -ri 's%^host all all 0\.0\.0\.0/0 trust$%host all all 0.0.0.0/0 md5%g' \ |
|
|
|
|
|
"$SERVICE_DATASTORE/var/lib/postgresql/data/pg_hba.conf" || return 1 |
|
|
|
|
|
|
|
|
|
|
|
docker restart "$container_id" || return 1 |
|
|
|
|
|
|
|
|
|
|
|
## XXXvlab: this won't help support multiple project running on the |
|
|
|
|
|
## same host |
|
|
|
|
|
cat <<EOF > "$DB_PASSFILE" |
|
|
|
|
|
*:*:*:postgres:$POSTGRES_ROOT_PASSWORD |
|
|
|
|
|
EOF |
|
|
|
|
|
chmod 600 "$DB_PASSFILE" || return 1 |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ddb () { dcmd psql -qAt "$@"; } |
|
|
ddb () { dcmd psql -qAt "$@"; } |
|
@ -104,6 +142,11 @@ db_change_password() { |
|
|
|
|
|
|
|
|
db_grant_rights () { |
|
|
db_grant_rights () { |
|
|
local dbname="$1" user="$2" |
|
|
local dbname="$1" user="$2" |
|
|
|
|
|
PGM chown "$user" "$dbname" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PGM() { |
|
|
|
|
|
local src="$1" dst="$2" |
|
|
require psql || apt-get install -y postgresql-client </dev/null |
|
|
require psql || apt-get install -y postgresql-client </dev/null |
|
|
require pgm || { |
|
|
require pgm || { |
|
|
( |
|
|
( |
|
@ -115,6 +158,9 @@ db_grant_rights () { |
|
|
# git checkout master |
|
|
# git checkout master |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
debug PGHOST="$DOCKER_IP" PGUSER=postgres pgm chown "$user" "$dbname" |
|
|
|
|
|
PGHOST="$DOCKER_IP" PGUSER=postgres prefix_pg_local_command=" " pgm chown "$user" "$dbname" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ensure_db_docker_running </dev/null || return 1 |
|
|
|
|
|
|
|
|
|
|
|
debug pgm "$@" |
|
|
|
|
|
pgm "$@" |
|
|
} |
|
|
} |