paulbsd-salt/states/haproxy/scripts/state.lua

42 lines
893 B
Lua
Raw Normal View History

2024-03-23 17:44:23 +01:00
local sleep_secs = 15
2023-06-06 09:23:53 +02:00
local args = table.pack(...)
if args[1] ~= nil then sleep_secs = args[1] end
function create_state()
local try = 0
local lastconns = 0
while true do
if lastconns == core.get_info()["CumConns"] then
try = try+1
end
2023-06-10 10:02:59 +02:00
local s = core.tcp()
local c = s:connect("127.0.0.1:9990")
local sent = s:send("show servers state\n")
local content,err = s:receive("*a")
s:close()
2023-06-06 09:23:53 +02:00
if content ~= nil then
if #content>0 then
local f = io.open("/var/run/haproxy.state","w")
f:write(content)
io.close(f)
end
end
lastconns = core.get_info()["CumConns"]
if try == 10 then
2024-05-25 13:54:44 +02:00
local msg = string.format("Worker with pid %s exited for create_state task",core.get_info()["Pid"])
2023-06-06 09:23:53 +02:00
print(msg)
core.done(msg)
end
core.sleep(sleep_secs)
end
end
core.register_task(create_state)