4 from pprint import pprint
13 from tsprint import print
18 # Service check url initial delay, delay, dockername
19 services["analysis"] = ["http://analysis:8081/health", 30, 15, "analysis"]
20 services["camunda"] = ["http://camunda:8085/engine-rest/process-instance/", 300, 15, "camunda"]
21 services["reporting"] = ["http://reporting:8083/health", 30, 15, "reporting"]
22 services["twitter"] = ["http://twitter:8084/actuator/health", 60, 15, "twitter"]
23 services["website"] = ["http://website:8080/", 30, 15, "website"]
29 def check_service(servicename):
31 # print(servicename+" -- checking service.")
33 r = requests.get(services[servicename][0], timeout=3)
34 if r.status_code != 200:
35 raise Exception("errorcode != 200: "+int(r.status_code))
37 print("+ "+servicename+" -- looks good :)")
40 th = threading.Timer(services[servicename][2], check_service, args=[servicename])
41 th.setName('failover_'+servicename)
44 print("- "+servicename+" -- looks bad :( "+str(sys.exc_info()[0]))
45 reset_service(servicename)
47 # schedule next check using startup delay
48 th = threading.Timer(services[servicename][1], check_service, args=[servicename])
49 th.setName('failover_'+servicename)
54 def reset_service(servicename):
57 print(" "+servicename+" -- restarting service")
59 docker_ctl.containers.client.api.restart(services[servicename][3], timeout=1)
61 print("! Docker said NO/service restart failed."+str(sys.exc_info()[0]))
65 if __name__ == "__main__":
66 def signal_handler(signal, frame):
67 print('SIG received. exitting!')
69 signal.signal(signal.SIGINT, signal_handler)
71 docker_ctl = docker.from_env()
72 print(docker_ctl.info())
75 print("####################")
76 print("# Failover service #")
77 print("####################")
82 print("Starting watchers")
84 for servicename, service in services.items():
85 th = threading.Timer(service[1], check_service, args=[servicename])
86 th.setName('failover_'+servicename)