blob: ebd8ea5c84be45ddc4e243f0d7d9d7f6f73ceed4 (
plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/usr/bin/python
import subprocess
#from time import sleep
import time
from datetime import datetime
import sys
beStat=0
BE_IP="<%= @be_ip %>"
BE_PORT="<%= @be_port %>"
PROTOCOL="<%= @protocol %>"
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 -k -s -o /dev/null -I -w \"%{http_code}\" -i "+PROTOCOL+"://" + BE_IP + ":" + BE_PORT + "/sdc2/rest/v1/user/jh0003"
proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
(out, err) = proc.communicate()
result = out.strip()
return str(result, "UTF-8")
##############################
# 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
sys.exit(1)
|