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