On 1/8/20 10:54 PM, Tim Duesterhus wrote:
List,
while working on updating my haproxy-auth-request [1] to make use of
haproxy-lua-http [2] instead of the crappy lua-socket [3] I realized
that it would be difficult for the administrator to use the script
afterwards.
The reason is that `require` in Lua attempts to search the modules
either in the current working directory (which is different from
the filename of the script executing the `require` and which most
likely is not anywhere near HAProxy's configuration folder) or within
Lua's library path which is compiled into Lua (in my case this is
something like `/usr/share/lua/5.3/`).
Add a `lua-prepend-path` configuration option that prepend the given
string to Lua's path, allowing scripts loaded with `lua-load` to find
libraries within that path.
Example configuration:
global
lua-prepend-path /etc/haproxy/lua-modules/?/init.lua
lua-prepend-path /etc/haproxy/lua-modules/?.lua
lua-load /etc/haproxy/lua-modules/auth-request.lua
Hey Tim,
For what is worth, we solve situations like this with regular script,
loaded before main script:
global
lua-load /path/to/config.lua
lua-load /path/to/app.lua
Inside config.lua you can override your app configuration options like this
conf = { opt1 = "val" }
Then, app.lua contains the following pattern
if not conf then
conf = { ... } -- defaults
else
if not conf.opt1 then conf.opt1 = "val" end
...
end
And now for the main topic, if you need to set any paths for Lua
scripts/libraries in non standard locations, you can directly use
package.path in config.lua script
package.path = package.path .. ';/some/path/?.lua'
That way, there is no need for users to edit app script, and they can
override configuration or Lua path settings. IMO, we don't need another
directive in HAProxy just to set Lua paths.
Best regards
--
Adis Nezirovic
Software Engineer
HAProxy Technologies - Powering your uptime!
375 Totten Pond Road, Suite 302 | Waltham, MA 02451, US
+1 (844) 222-4340 | https://www.haproxy.com