-
Notifications
You must be signed in to change notification settings - Fork 300
/
signalmlb.lua
40 lines (34 loc) · 1.28 KB
/
signalmlb.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
40
-- A simple Lua module for HAProxy that sends signals to the marathon-lb process
function run(cmd)
local file = io.popen(cmd)
local output = file:read('*a')
local success, _, code = file:close()
return output, success, code
end
function send_response(applet, code, response)
applet:set_status(code)
applet:add_header("content-length", string.len(response))
applet:add_header("content-type", "text/plain")
applet:start_response()
applet:send(response)
end
core.register_service("signalmlbhup", "http", function(applet)
local _, success, code = run("pkill -HUP -f '^python.*marathon_lb.py'")
if not success then
send_response(applet, 500, string.format(
"Failed to send SIGHUP signal to marathon-lb (exit code %d). Is \z
marathon-lb running in 'poll' mode?", code))
return
end
send_response(applet, 200, "Sent SIGHUP signal to marathon-lb")
end)
core.register_service("signalmlbusr1", "http", function(applet)
local _, success, code = run("pkill -USR1 -f '^python.*marathon_lb.py'")
if not success then
send_response(applet, 500, string.format(
"Failed to send SIGUSR1 signal to marathon-lb (exit code %d). Is \z
marathon-lb running in 'poll' mode?", code))
return
end
send_response(applet, 200, "Sent SIGUSR1 signal to marathon-lb")
end)