Skip to content

Commit

Permalink
Call post_init.sh on promote (#238)
Browse files Browse the repository at this point in the history
This way we can make sure that the recent version of user_management and monitoring functions are deployed.
  • Loading branch information
CyberDem0n committed May 29, 2018
1 parent 915a9d1 commit 9eb9f1e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions postgres-appliance/scripts/configure_spilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,14 @@ def deep_update(a, b):
replication:
username: {{PGUSER_STANDBY}}
password: '{{PGPASSWORD_STANDBY}}'
{{#CALLBACK_SCRIPT}}
callbacks:
{{#CALLBACK_SCRIPT}}
on_start: {{CALLBACK_SCRIPT}}
on_stop: {{CALLBACK_SCRIPT}}
on_role_change: {{CALLBACK_SCRIPT}}
on_role_change: '/scripts/on_role_change.sh {{HUMAN_ROLE}} {{CALLBACK_SCRIPT}}'
{{/CALLBACK_SCRIPT}}
{{^CALLBACK_SCRIPT}}
on_role_change: '/scripts/on_role_change.sh {{HUMAN_ROLE}} true'
{{/CALLBACK_SCRIPT}}
{{#USE_WALE}}
create_replica_method:
Expand Down
19 changes: 19 additions & 0 deletions postgres-appliance/scripts/on_role_change.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

readonly HUMAN_ROLE=$1
shift

"$@"


readonly dbname=postgres
if [[ "${*: -3:1}" == "on_role_change" && "${*: -2:1}" == "master" ]]; then
num=30 # wait 30 seconds for end of recovery
while [[ $((num--)) -gt 0 ]]; do
if [[ "$(psql -d $dbname -tAc 'SELECT pg_is_in_recovery()')" == "f" ]]; then
exec /scripts/post_init.sh "$HUMAN_ROLE" "$dbname"
else
sleep 1
fi
done
fi

0 comments on commit 9eb9f1e

Please sign in to comment.