newer pg module
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / files / validate_postgresql_connection.sh
diff --git a/3rdparty/modules/postgresql/files/validate_postgresql_connection.sh b/3rdparty/modules/postgresql/files/validate_postgresql_connection.sh
new file mode 100644 (file)
index 0000000..1c3506c
--- /dev/null
@@ -0,0 +1,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