Skip to content

Commit 060ea8e

Browse files
mvachbgandon
andcommitted
Implement a drain script for postgres 10 properly use the fast shutdown mode
Co-authored-by: Benjamin Gandon <benjamin.gandon@sap.com>
1 parent e349e11 commit 060ea8e

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

jobs/postgres-10/spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ templates:
77
create-database.erb: bin/create-database
88
postgres.erb: bin/postgres
99
postgresql.conf.erb: config/postgresql.conf
10+
drain.erb: bin/drain
1011

1112
packages:
1213
- postgres-10
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
# If a command fails, in a pipeline or not, exit immediately
4+
set -e -o pipefail
5+
6+
function prepend_datetime() {
7+
awk -W interactive '{ system("echo -n [$(date +%FT%T%z)]"); print " " $0 }'
8+
}
9+
10+
# Before redirecting stdout and stderr, copy the file descriptor for original
11+
# stdout where BOSH is expecting an integer, and only that.
12+
exec 3>&1
13+
exec \
14+
1> >(prepend_datetime >> /var/vcap/sys/log/postgres-10/drain.out.log) \
15+
2> >(prepend_datetime >> /var/vcap/sys/log/postgres-10/drain.err.log)
16+
17+
output_for_bosh() {
18+
exit_code=$?
19+
20+
if [ $exit_code -eq 0 ]; then
21+
echo "postgres-10 deamon is properly shutdown with Fast Shutdown mode (SIGINT)"
22+
else
23+
echo "drain failed"
24+
fi
25+
26+
echo $exit_code >&3
27+
}
28+
29+
trap output_for_bosh EXIT
30+
31+
32+
postgres_pid=$(/var/vcap/packages/bpm/bin/bpm pid postgres-10)
33+
kill -s SIGINT "${postgres_pid}"

0 commit comments

Comments
 (0)