* debian/pg_createcluster_patroni: Allow re-creating configuration file for

already existing clusters/ports, patch by Tomas Pospisek (Closes: #953162).
This commit is contained in:
Michael Banck 2020-05-07 11:58:40 +02:00
parent 7bd32192af
commit 6fee48f191
2 changed files with 25 additions and 6 deletions

3
debian/changelog vendored
View file

@ -1,5 +1,8 @@
patroni (1.6.5-2) UNRELEASED; urgency=medium
[ Michael Banck ]
* debian/pg_createcluster_patroni: Allow re-creating configuration file for
already existing clusters/ports, patch by Tomas Pospisek (Closes: #953162).
-- Debian PostgreSQL Maintainers <team+postgresql@tracker.debian.org> Mon, 27 Apr 2020 18:25:04 +0200

View file

@ -58,16 +58,32 @@ else
CLUSTER=$2
fi
# find port of the cluster if it is already running
EXISTING_PORT=$(pg_lsclusters -h | grep -E "^$VERSION[[:space:]]+$CLUSTER[[:space:]]+" | awk '{print $3}')
if [ -z "$PORT" ]; then
# try to guess next free port
PORT=$(($(pg_lsclusters -h | awk '{print $3}' | sort -n | tail -1) + 1))
if [ "$PORT" -eq 1 ]; then
# No cluster exists yet, use default port
PORT=5432
# no port was specified
if [ -n "$EXISTING_PORT" ]; then
# if our cluster is already running yet, then reuse the same port
PORT="$EXISTING_PORT"
else
# if our cluster isn't running yet, try to guess next free port
PORT=$(($(pg_lsclusters -h | awk '{print $3}' | sort -n | tail -1) + 1))
if [ "$PORT" -eq 1 ]; then
# No cluster exists yet, use default port
PORT=5432
fi
fi
else
# validate specified port
pg_lsclusters | awk '{print $3}' | grep -q $PORT && echo "Port $PORT already in use" && exit 1
if [ "$PORT" = "$EXISTING_PORT" ]; then
# reuse existing port
true
else
# fail if port is already in use
pg_lsclusters -h | awk '{print $3}' | grep -q $PORT && echo "Port $PORT already in use" && exit 1
fi
fi
# determine API port (default is 8008) by incrementing for each additional