49d82666304e4075d089bafaf1af6f7f1aba83a9
[sdc.git] /
1 #!/usr/bin/python
2 import subprocess
3 #from time import sleep
4 import time
5 from datetime import datetime
6
7 beStat=0
8 BE_IP="<%= @be_ip %>"
9
10 class bcolors:
11     HEADER    = '\033[95m'
12     OKBLUE    = '\033[94m'
13     OKGREEN   = '\033[92m'
14     WARNING   = '\033[93m'
15     FAIL      = '\033[91m'
16     ENDC      = '\033[0m'
17     BOLD      = '\033[1m'
18     UNDERLINE = '\033[4m'
19
20
21 ##############################
22 #    Functions
23 ##############################
24 def checkBackend():
25     command="curl -s -o /dev/null -I -w \"%{http_code}\" -i http://" + BE_IP + ":8080/sdc2/rest/v1/user/jh0003"
26
27     proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
28     (out, err) = proc.communicate()
29     result = out.strip()
30     return result
31
32 ##############################
33 #    Main
34 ##############################
35
36 for i in range(1,10):
37     myResult = checkBackend()
38     if myResult == '200':
39         print '[INFO]: Backend is up and running'
40         beStat=1
41         break
42     else:
43         currentTime = datetime.now()
44         print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' Backend not responding, try #' + str(i) + bcolors.ENDC
45         time.sleep(10)
46
47 if beStat == 0:
48     print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'Backend is DOWN :-(' + bcolors.ENDC
49     exit()