Skip to content
This repository was archived by the owner on Nov 18, 2017. It is now read-only.

Commit 4720cb3

Browse files
committed
check etcd for haproxy status instead of Postgres
1 parent 4871a25 commit 4720cb3

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

haproxy_status.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
3+
from BaseHTTPServer import BaseHTTPRequestHandler
4+
from helpers.etcd import Etcd
5+
from helpers.postgresql import Postgresql
6+
import sys, yaml, socket
7+
8+
f = open(sys.argv[1], "r")
9+
config = yaml.load(f.read())
10+
f.close()
11+
12+
etcd = Etcd(config["etcd"])
13+
postgresql = Postgresql(config["postgresql"])
14+
15+
class StatusHandler(BaseHTTPRequestHandler):
16+
def do_GET(self):
17+
return self.do_ANY()
18+
def do_OPTIONS(self):
19+
return self.do_ANY()
20+
def do_ANY(self):
21+
if postgresql.name == etcd.current_leader()["hostname"]:
22+
self.send_response(200)
23+
else:
24+
self.send_response(503)
25+
self.end_headers()
26+
self.wfile.write('\r\n')
27+
return
28+
29+
try:
30+
from BaseHTTPServer import HTTPServer
31+
host, port = config["haproxy_status"]["listen"].split(":")
32+
server = HTTPServer((host, int(port)), StatusHandler)
33+
print 'listening on %s:%s' % (host, port)
34+
server.serve_forever()
35+
except KeyboardInterrupt:
36+
print('^C received, shutting down server')
37+
server.socket.close()

haproxy_status.sh

-16
This file was deleted.

postgres0.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ etcd:
33
scope: batman
44
ttl: 30
55
host: 127.0.0.1:4001
6+
haproxy_status:
7+
listen: 127.0.0.1:15432
68
postgresql:
79
name: postgresql0
810
listen: 127.0.0.1:5432

postgres1.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ etcd:
33
scope: batman
44
ttl: 30
55
host: 127.0.0.1:4001
6+
haproxy_status:
7+
listen: 127.0.0.1:15433
68
postgresql:
79
name: postgresql1
810
listen: 127.0.0.1:5433

0 commit comments

Comments
 (0)