forked from compose/governor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
haproxy_status.py
executable file
·37 lines (32 loc) · 1.02 KB
/
haproxy_status.py
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
#!/usr/bin/env python
from BaseHTTPServer import BaseHTTPRequestHandler
from helpers.etcd import Etcd
from helpers.postgresql import Postgresql
import sys, yaml, socket
f = open(sys.argv[1], "r")
config = yaml.load(f.read())
f.close()
etcd = Etcd(config["etcd"])
postgresql = Postgresql(config["postgresql"])
class StatusHandler(BaseHTTPRequestHandler):
def do_GET(self):
return self.do_ANY()
def do_OPTIONS(self):
return self.do_ANY()
def do_ANY(self):
if postgresql.name == etcd.current_leader()["hostname"]:
self.send_response(200)
else:
self.send_response(503)
self.end_headers()
self.wfile.write('\r\n')
return
try:
from BaseHTTPServer import HTTPServer
host, port = config["haproxy_status"]["listen"].split(":")
server = HTTPServer((host, int(port)), StatusHandler)
print 'listening on %s:%s' % (host, port)
server.serve_forever()
except KeyboardInterrupt:
print('^C received, shutting down server')
server.socket.close()