Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions 9.4/root/usr/libexec/check-container
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /bin/sh

# Try whether the PostgreSQL in container accepts connections.
#
# With --live, be tolerant to starting PG server. If the /bin/postgres binary
# has not been executed yet (the shell script is initializing the container),
# wait for it (this script might run forever, we expect that the timeout is
# maintained externally).

test -z "$ENABLED_COLLECTIONS" || . scl_source enable $ENABLED_COLLECTIONS

check=ready
case $1 in
--live) check=live ;;
esac

while true; do
# Wait until the /bin/postgres is executed.
case $(readlink -f /proc/1/exe) in
*bash) sleep 0.2; continue ;;
*) break ;;
esac
done

# Timeout is infinite (openshift template has the timeout pre-set)
pg_isready -q \
-h 127.0.0.1 \
${POSTGRESQL_USER+-U "$POSTGRESQL_USER"} \
${POSTGRESQL_DATABASE+-d "$POSTGRESQL_DATABASE"} \
--timeout 0
rc=$?

# we are ready only if the db accepts connections
test $rc -eq 0 && exit 0

# container is live also during pg cluster start-up
test $rc -eq 1 && test $check = live && exit 0

exit 1
39 changes: 39 additions & 0 deletions 9.5/root/usr/libexec/check-container
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /bin/sh

# Try whether the PostgreSQL in container accepts connections.
#
# With --live, be tolerant to starting PG server. If the /bin/postgres binary
# has not been executed yet (the shell script is initializing the container),
# wait for it (this script might run forever, we expect that the timeout is
# maintained externally).

test -z "$ENABLED_COLLECTIONS" || . scl_source enable $ENABLED_COLLECTIONS

check=ready
case $1 in
--live) check=live ;;
esac

while true; do
# Wait until the /bin/postgres is executed.
case $(readlink -f /proc/1/exe) in
*bash) sleep 0.2; continue ;;
*) break ;;
esac
done

# Timeout is infinite (openshift template has the timeout pre-set)
pg_isready -q \
-h 127.0.0.1 \
${POSTGRESQL_USER+-U "$POSTGRESQL_USER"} \
${POSTGRESQL_DATABASE+-d "$POSTGRESQL_DATABASE"} \
--timeout 0
rc=$?

# we are ready only if the db accepts connections
test $rc -eq 0 && exit 0

# container is live also during pg cluster start-up
test $rc -eq 1 && test $check = live && exit 0

exit 1
10 changes: 5 additions & 5 deletions examples/postgresql-ephemeral-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@
"timeoutSeconds": 1,
"initialDelaySeconds": 5,
"exec": {
"command": [ "/bin/sh", "-i", "-c", "psql -h 127.0.0.1 -U $POSTGRESQL_USER -q -d $POSTGRESQL_DATABASE -c 'SELECT 1'"]
"command": [ "/usr/libexec/check-container" ]
}
},
"livenessProbe": {
"timeoutSeconds": 10,
"initialDelaySeconds": 120,
"exec": {
"command": [ "/bin/sh", "-i", "-c", "pg_isready -h 127.0.0.1 -p 5432" ]
},
"timeoutSeconds": 1,
"initialDelaySeconds": 30
"command": [ "/usr/libexec/check-container", "--live" ]
}
},
"env": [
{
Expand Down
10 changes: 5 additions & 5 deletions examples/postgresql-persistent-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@
"timeoutSeconds": 1,
"initialDelaySeconds": 5,
"exec": {
"command": [ "/bin/sh", "-i", "-c", "psql -h 127.0.0.1 -U $POSTGRESQL_USER -q -d $POSTGRESQL_DATABASE -c 'SELECT 1'"]
"command": [ "/usr/libexec/check-container" ]
}
},
"livenessProbe": {
"timeoutSeconds": 10,
"initialDelaySeconds": 120,
"exec": {
"command": [ "/bin/sh", "-i", "-c", "pg_isready -h 127.0.0.1 -p 5432" ]
},
"timeoutSeconds": 1,
"initialDelaySeconds": 30
"command": [ "/usr/libexec/check-container", "--live" ]
}
},
"env": [
{
Expand Down
20 changes: 10 additions & 10 deletions examples/replica/postgresql_replica.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@
"timeoutSeconds": 1,
"initialDelaySeconds": 5,
"exec": {
"command": [ "/bin/sh", "-i", "-c", "psql -h 127.0.0.1 -U $POSTGRESQL_USER -q -d $POSTGRESQL_DATABASE -c 'SELECT 1'"]
"command": [ "/usr/libexec/check-container" ]
}
},
"livenessProbe": {
"timeoutSeconds": 10,
"initialDelaySeconds": 120,
"exec": {
"command": [ "/bin/sh", "-i", "-c", "pg_isready -h 127.0.0.1 -p 5432" ]
},
"timeoutSeconds": 1,
"initialDelaySeconds": 30
"command": [ "/usr/libexec/check-container", "--live" ]
}
},
"env": [
{
Expand Down Expand Up @@ -318,15 +318,15 @@
"timeoutSeconds": 1,
"initialDelaySeconds": 5,
"exec": {
"command": [ "/bin/sh", "-i", "-c", "psql -h 127.0.0.1 -U $POSTGRESQL_USER -q -d $POSTGRESQL_DATABASE -c 'SELECT 1'"]
"command": [ "/usr/libexec/check-container" ]
}
},
"livenessProbe": {
"timeoutSeconds": 10,
"initialDelaySeconds": 120,
"exec": {
"command": [ "/bin/sh", "-i", "-c", "pg_isready -h 127.0.0.1 -p 5432" ]
},
"timeoutSeconds": 1,
"initialDelaySeconds": 30
"command": [ "/usr/libexec/check-container", "--live" ]
}
},
"env": [
{
Expand Down
39 changes: 39 additions & 0 deletions latest/root/usr/libexec/check-container
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /bin/sh

# Try whether the PostgreSQL in container accepts connections.
#
# With --live, be tolerant to starting PG server. If the /bin/postgres binary
# has not been executed yet (the shell script is initializing the container),
# wait for it (this script might run forever, we expect that the timeout is
# maintained externally).

test -z "$ENABLED_COLLECTIONS" || . scl_source enable $ENABLED_COLLECTIONS

check=ready
case $1 in
--live) check=live ;;
esac

while true; do
# Wait until the /bin/postgres is executed.
case $(readlink -f /proc/1/exe) in
*bash) sleep 0.2; continue ;;
*) break ;;
esac
done

# Timeout is infinite (openshift template has the timeout pre-set)
pg_isready -q \
-h 127.0.0.1 \
${POSTGRESQL_USER+-U "$POSTGRESQL_USER"} \
${POSTGRESQL_DATABASE+-d "$POSTGRESQL_DATABASE"} \
--timeout 0
rc=$?

# we are ready only if the db accepts connections
test $rc -eq 0 && exit 0

# container is live also during pg cluster start-up
test $rc -eq 1 && test $check = live && exit 0

exit 1