haproxy lua程序的生命周期
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了haproxy lua程序的生命周期相关的知识,希望对你有一定的参考价值。
The Lua code is loaded in one or more files. These files contains main code and functions. Lua have 6 execution context.
-
The Lua file body context. It is executed during the load of the Lua file in the HAProxy [global] section with the directive lua-load. It is executed in initialisation mode. This section is use for configuring Lua bindings in HAProxy.
-
The Lua init context. It is a Lua function executed just after the HAProxy configuration parsing. The execution is in initialisation mode. In this context the HAProxy environment are already initialized. It is useful to check configuration, or initializing socket connections or tasks. These functions are declared in the body context with the Lua function core.register_init(). The prototype of the function is a simple function without return value and without parameters, like this: function fcn().
-
The Lua task context. It is a Lua function executed after the start of the HAProxy scheduler, and just after the declaration of the task with the Lua function core.register_task(). This context can be concurrent with the traffic processing. It is executed in runtime mode. The prototype of the function is a simple function without return value and without parameters, like this: function fcn().
-
The action context. It is a Lua function conditionally executed. These actions are registered by the Lua directives “core.register_action()”. The prototype of the Lua called function is a function with doesn’t returns anything and that take an object of class TXN as entry. function fcn(txn).
-
The sample-fetch context. This function takes a TXN object as entry argument and returns a string. These types of function cannot execute any blocking function. They are useful to aggregate some of original HAProxy sample-fetches and return the result. The prototype of the function is function string fcn(txn). These functions can be registered with the Lua function core.register_fetches(). Each declared sample-fetch is prefixed by the string “lua.”.
NOTE: It is possible that this function cannot found the required data in the original HAProxy sample-fetches, in this case, it cannot return the result. This case is not yet supported
-
The converter context. It is a Lua function that takes a string as input and returns another string as output. These types of function are stateless, it cannot access to any context. They don’t execute any blocking function. The call prototype is function string fcn(string). This function can be registered with the Lua function core.register_converters(). Each declared converter is prefixed by the string “lua.”.
以上是关于haproxy lua程序的生命周期的主要内容,如果未能解决你的问题,请参考以下文章