diff --git a/tool/net/help.txt b/tool/net/help.txt index 03c054d23..128a0feb7 100644 --- a/tool/net/help.txt +++ b/tool/net/help.txt @@ -554,6 +554,12 @@ HOOKS each time redbean reaps a child connection process using wait4(). This won't be called in uniprocess mode. + OnServerHeartbeat() + If this function is defined it'll be called from the main process + on each server heartbeat. The heartbeat interval is configurable + with ProgramHeartbeatInterval. If this hook is defined, then + `/.heartbeat.lua` is not called. + OnServerListen(socketdescriptor:int,serverip:int,serverport:int) → bool If this function is defined it'll be called from the main process before redbean starts listening on a port. This hook can be used diff --git a/tool/net/redbean.c b/tool/net/redbean.c index dc9b3c48f..c32594f34 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -5745,7 +5745,11 @@ static void HandleHeartbeat(void) { Reindex(); getrusage(RUSAGE_SELF, &shared->server); #ifndef STATIC - LuaRunAsset("/.heartbeat.lua", false); + if (IsHookDefined("OnServerHeartbeat")) { + CallSimpleHook("OnServerHeartbeat"); + } else { + LuaRunAsset("/.heartbeat.lua", false); + } CollectGarbage(); #endif for (i = 1; i < servers.n; ++i) {