File: validate_postgresql_connection.sh

package info (click to toggle)
puppet-module-puppetlabs-postgresql 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 980 kB
  • sloc: ruby: 5,047; sh: 52; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 357 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/sh

# usage is: validate_db_connection 2 50 psql

SLEEP=$1
TRIES=$2
PSQL=$3

STATE=1

c=1

while [ $c -le $TRIES ]
do
  echo $c
  if [ $c -gt 1 ]
  then
    echo 'sleeping'
    sleep $SLEEP
  fi

  /bin/echo "SELECT 1" | $PSQL
  STATE=$?

  if [ $STATE -eq 0 ]
  then
    exit 0
  fi
  c=$((c+1))
done

echo 'Unable to connect to postgresql'

exit 1