aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/check_Backend_Health.py.erb
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/check_Backend_Health.py.erb')
-rw-r--r--catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/check_Backend_Health.py.erb48
1 files changed, 48 insertions, 0 deletions
diff --git a/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/check_Backend_Health.py.erb b/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/check_Backend_Health.py.erb
new file mode 100644
index 0000000000..b1132c0aeb
--- /dev/null
+++ b/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/check_Backend_Health.py.erb
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+import subprocess
+#from time import sleep
+import time
+from datetime import datetime
+
+BE_IP="<%= @be_ip %>"
+
+class bcolors:
+ HEADER = '\033[95m'
+ OKBLUE = '\033[94m'
+ OKGREEN = '\033[92m'
+ WARNING = '\033[93m'
+ FAIL = '\033[91m'
+ ENDC = '\033[0m'
+ BOLD = '\033[1m'
+ UNDERLINE = '\033[4m'
+
+
+##############################
+# Functions
+##############################
+def checkBackend():
+ command="curl -s -o /dev/null -I -w \"%{http_code}\" -i http://" + BE_IP + ":8080/sdc2/rest/v1/user/jh0003"
+
+ proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
+ (out, err) = proc.communicate()
+ result = out.strip()
+ return result
+
+##############################
+# Main
+##############################
+
+for i in range(1,10):
+ myResult = checkBackend()
+ if myResult == '200':
+ print '[INFO]: Backend is up and running'
+ beStat=1
+ break
+ else:
+ currentTime = datetime.now()
+ print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' Backend not responding, try #' + str(i) + bcolors.ENDC
+ time.sleep(10)
+
+if beStat == 0:
+ print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'Backend is DOWN :-(' + bcolors.ENDC
+ exit() \ No newline at end of file