forked from d2iq-archive/marathon-lb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getconfig.lua
39 lines (34 loc) · 906 Bytes
/
getconfig.lua
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
-- A simple Lua script which serves up the HAProxy
-- config as it was at init time.
function read_config_file(cmdline)
local found = false
local filename = ''
for s in string.gmatch(cmdline, '%g+') do
if s == '-f' then
found = true
elseif found then
filename = s
break
end
end
local f = io.open(filename, "rb")
local config = f:read("*all")
f:close()
return config
end
function load_config()
local f = io.open('/proc/self/cmdline', "rb")
local cmdline = f:read("*all")
f:close()
return read_config_file(cmdline)
end
core.register_init(function()
haproxy_config = load_config()
end)
core.register_service("getconfig", "http", function(applet)
applet:set_status(200)
applet:add_header("content-length", string.len(haproxy_config))
applet:add_header("content-type", "text/plain")
applet:start_response()
applet:send(haproxy_config)
end)