trafficserver-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Chaves <e...@uolet.com>
Subject ts_lua error after using ts.add_package_path
Date Wed, 06 Mar 2019 21:23:11 GMT
Hi folks,

This may be a little off-topic. Not sure if questions regarding lua
plugins/lua scripts should be asked here in the list. If so forgive me and
please point me the proper place to ask.

I'm trying to learn TS lua script's. At first I just followed the sample
code for reverse host header presented in the lua_plugin docs by writing a
module named my_module.lua required inside a do_remap() with the following
content:

*local my_module = {}*
*function my_module.send_response()*
*  ts.debug('executing my_module.send_response')*
*  ts.client_response.header['Rhost'] = ts.ctx['rhost']*
*  return 0*
*end*
*return my_module*

This works fine and after that I tried to add some code to connect into a
local redis instance using libs installed by luarocks (eg.: luarocks
install --tree /opt/ats/lua_modules luasocket)

 I found some scripts at github that uses the ts.add_package_path to
include the new modules and based on them I added those two lines at the
top of my_module.lua:

*ts.add_package_path('/opt/ats/lua_modules/share/lua/5.1/?.lua;/opt/ats/lua_modules/share/lua/5.1/?/init.lua')*
*ts.add_package_cpath('/opt/ats/lua_modules/share/lua/5.1/?.so')*

By doing so, even without actually requiring any new module (ie no other
changes in my_module logic) when my do_remap tries require my_module, I got
an error: *ERROR: [ts_lua] lua_pcall failed:
/opt/ats/lua-plugins/my_module.lua:6: can't get the instance conf*

So it's clear that I'm breaking something using the ts.add_package_path.
I've also tried to mangle with package.path variable with the same outcome.

What am I doing wrong and how should I do to add those new packages?

Cheers,

Eric

Mime
View raw message