Hi! Cant wrap around how to configure haProxy.
Main idea is, i have main server and backup server, if main is down i need to post few request to startup the backup server, this has to be done just once, until i manually return primary to working state and reload haproxy.
I find this approach configs, witch doesn’t suite, because it returns the lua response instead of backup backend response.
global
log /dev/log local0
log /dev/log local1 notice
daemon
lua-load t.lua
defaults
log global
mode http
option httplog
timeout connect 5000
timeout client 50000
timeout server 50000
frontend front_9001
bind *:9001
default_backend back_9001
http-request lua.log_primary_status
backend back_9001
mode http
option httpchk GET /api/v2/BaseInfo
http-check expect status 200
option persist
option allbackups
server primary 10.0.0.35:9001 check fall 3 rise 2 inter 5s shutdown-sessions
server backup 10.0.0.36:9001 backup check
and in lua for test for example
function log(message)
local file = io.open("/var/log/haproxy_status.log", "a")
file:write(os.date("%Y-%m-%d %H:%M:%S") .. " - " .. message .. "\n")
file:close()
end
-- This function will be called with each request to log the primary server status
core.register_action("log_primary_status", { "http-req", "tcp-req" }, function(txn)
local backend = core.backends["back_9001"]
local primary_server = backend.servers["primary"]
-- Check if the primary server is down
if primary_server and primary_server:get_state() == "DOWN" then
log("Primary server is down - Health check failed.")
else
log("Primary server is up.")
end
end)
-- Log when the Lua script is loaded
log("Lua script loaded. Version: " .. os.time())
So is there a way to execute lua method in here
server primary 10.0.0.35:9001 check fall 3 rise 2 inter 5s shutdown-sessions
to startup the backup itself, log alert and so on with lua, and then remember that we did that, and even if the primary is back alive, return responces from backup untill manual restart?