forked from d2iq-archive/marathon-lb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetpids.lua
More file actions
23 lines (21 loc) · 666 Bytes
/
getpids.lua
File metadata and controls
23 lines (21 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- A simple Lua module for HAProxy which returns
-- a list of all the current HAProxy PIDs by using
-- the unix `pidof` command.
-- :)
function os.capture(cmd)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
core.register_service("getpids", "http", function(applet)
local response = os.capture("pidof haproxy", false)
applet:set_status(200)
applet:add_header("content-length", string.len(response))
applet:add_header("content-type", "text/plain")
applet:start_response()
applet:send(response)
end)