Last active
January 8, 2022 17:20
-
-
Save r4um/869cbbd52641b80bd737f69bf72f676e to your computer and use it in GitHub Desktop.
meh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A simple Lua script which serves up the HAProxy config md5 | |
-- ubuntu install the lua-md5 package | |
-- ripped from https://github.com/mesosphere/marathon-lb/blob/master/getconfig.lua | |
md5 = require 'md5' | |
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() | |
haproxy_config_md5 = md5.sumhexa(haproxy_config) | |
end) | |
core.register_service("getconfigmd5", "http", function(applet) | |
applet:set_status(200) | |
applet:add_header("content-length", string.len(haproxy_config_md5)) | |
applet:add_header("content-type", "text/plain") | |
applet:start_response() | |
applet:send(haproxy_config_md5) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment