Using Lua package (LuaSocket) with HAProxy - lua

I have installed HAProxy with Lua 5.3.1, and also LuaSocket.
I have LUA_PATH and LUA_CPATH defined:
export LUA_PATH="/usr/local/share/lua/5.3/?.lua;?.lua"
export LUA_CPATH="/usr/local/lib/lua/5.3/?.so;?.so"
and I'm using LuaSocket in my .lua file
core.register_fetches("myfunc", function(txn)
...
local http = require("socket.http")
r, e = http.request("http://localhost:5001/api/Registry/")
however I can see from journalctl -xe that it isn't working
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: [ALERT] 344/232733 (16734) : Lua sample-fetch 'myfunc': runtime error: /home/ubuntu/haproxy-mapping.lua:12: module 'socket.http' not found:
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no field package.preload['socket.http']
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file '/usr/local/share/lua/5.3/socket/http.lua'
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file '/usr/local/share/lua/5.3/socket/http/init.lua'
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file '/usr/local/lib/lua/5.3/socket/http.lua'
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file '/usr/local/lib/lua/5.3/socket/http/init.lua'
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file './socket/http.lua'
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file './socket/http/init.lua'
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file '/usr/local/lib/lua/5.3/socket/http.so'
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file '/usr/local/lib/lua/5.3/loadall.so'
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file './socket/http.so'
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file '/usr/local/lib/lua/5.3/socket.so'
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file '/usr/local/lib/lua/5.3/loadall.so'
Dec 11 23:27:33 ip-172-31-5-92 haproxy[16731]: no file './socket.so' from [C] global 'require', /home/ubuntu/haproxy-mapping.lua:12 C function line 4.
I'm surprised that it cannot find /usr/local/share/lua/5.3/socket/http.lua because it's there:
me$ ls -l /usr/local/share/lua/5.3/socket
total 56
-rw-r--r-- 1 root root 10640 Dec 11 21:31 ftp.lua
-rw-r--r-- 1 root root 3698 Dec 11 21:31 headers.lua
-rw-r--r-- 1 root root 14588 Dec 11 21:31 http.lua
-rw-r--r-- 1 root root 8074 Dec 11 21:31 smtp.lua
-rw-r--r-- 1 root root 3766 Dec 11 21:31 tp.lua
-rw-r--r-- 1 root root 11675 Dec 11 21:31 url.lua
It is saying
no file './socket.so' from [C] global 'require', /home/ubuntu/haproxy-mapping.lua:12 C function line 4.
is that the core of the issue? There is no socket.so on the machine
Update: forgot to mention that I can use LuaSocket from Lua directly, just not when it's embedded in HAProxy.
Update 2: I suspect permissions. I ran strace on it and found
open("/usr/local/share/lua/5.3/socket/http.lua", O_RDONLY) = -1 ENOENT (No such file or directory)
and I know that haproxy is running as the user haproxy
me :/usr/local/share/lua/5.3/socket$ ps -o user= -p 3273
haproxy
and yet if I switch user to haproxy I can read the file
me :/usr/local/share/lua/5.3/socket$ su - haproxy
Password:
No directory, logging in with HOME=/
$ more /usr/local/share/lua/5.3/socket/http.lua
...listing...
and I also changed owner of the http.lua file to haproxy and it still can't open the file.

I can only assume this is something to do with the context that the Lua function runs with-in when it is called, because changing the code to
local http = require("socket.http")
core.register_fetches("myfunc", function(txn)
...
worked.
UPDATE: according to this https://www.arpalert.org/src/haproxy-lua-api/1.7/index.html during initialization you can DNS lookups but in runtime mode you cannot. It doesn't say anything about files but it seems reasonable to believe you can't do files either.

Related

System checker fails on MacOS Big Sur with "Java is not reachable"

I'm having trouble running Cytoscape 3.9.1 on MacOS Big Sur. The system checker fails with the following:
############# Cytoscape System Requirements Checker for Mac ##############
Target Cytoscape version: 3.9.0
Your shell is bash
Compatible OS version found: 11.6
- Pass: OS Version = 11.6.1
- Pass: Following Oracle JDK found:
/Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk
Fail: Java is not reachable.
Try re-installing Java 11.
I have Java 11 installed at the location shown in the output, and it seems fine:
$ /Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home/bin/java -version
java version "11.0.5" 2019-10-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode)
Permissions look right (these are the same all the way up the directory hierarchy):
$ ls -lh /Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home/bin/
total 6672
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jaotc
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jar
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jarsigner
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 java
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 javac
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 javadoc
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 javap
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jcmd
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jconsole
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jdb
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jdeprscan
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jdeps
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jhsdb
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jimage
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jinfo
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jjs
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jlink
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jmap
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jmod
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jps
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jrunscript
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jshell
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jstack
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jstat
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 jstatd
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 keytool
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 pack200
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 rmic
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 rmid
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 rmiregistry
-rwxr-xr-x 1 root wheel 101K Oct 6 2019 serialver
-rwxr-xr-x 1 root wheel 110K Oct 6 2019 unpack200
I also have several more up-to-date Java versions installed (I'm not sure if these are causing the issue):
$ ls /Library/Java/JavaVirtualMachines/
jdk-10.0.2.jdk jdk-12.0.2.jdk jdk-14.0.1.jdk jdk1.8.0_181.jdk
jdk-11.0.5.jdk jdk-13.0.2.jdk jdk-17.0.1.jdk
The default is JDK17:
$ java -version
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
If I invoke cytoscape.sh directly from the command line, it appears to be trying to run under Java 8:
$ ./cytoscape.sh
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/cytoscape/launcher/internal/Launcher has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
Cytoscape 3.9.1 will not run on JDK 17. You need to set your JAVA_HOME to point to your JDK 11 installation and things should work.
-- scooter
I had a similar issue with Java. So I'm including my answer here if anyone else has the same issue as me.
First I went here to find out "How to set or change the default Java (JDK) version on macOS?"
From there you should be able to find out the Java version you want to use. Then set your JAVA_HOME variable
Using bash or zsh you can set your JAVA_HOME environment variable like so:
Bash Example
echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 11.0.7)" >> ~/.bash_profile
or in Zsh
echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 11.0.7)" >> ~/.zshrc
Restart terminal after this.
You can check your shell profile and see that this line has now been added to the end of the profile:
nano ~/.bash_profile
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home
You can also check that java is mapped to the desired Java version by default now:
java -version
Running the System Checker Script on Mac should now recognize Java is installed correctly
./mac.sh
Cytoscape should now run by clicking on the cytoscape.sh script

Lua can't import a module and says file not found but the file exists

i'm trying to run a lua script from inside haproxy that imports the "pgmoon" library. i can import pgmoon and get as far as opening a socket, but then i run into this:
[ALERT] 082/234313 (8) : Lua function 'queue-request': runtime error: /usr/local/share/lua/5.3/pgmoon/init.lua:269: module 'pgmoon.crypto' not found:
no field package.preload['pgmoon.crypto']
no file '/usr/local/share/lua/5.3/pgmoon/crypto.lua'
no file '/usr/local/share/lua/5.3/pgmoon/crypto/init.lua'
no file '/usr/local/lib/lua/5.3/pgmoon/crypto.lua'
no file '/usr/local/lib/lua/5.3/pgmoon/crypto/init.lua'
no file '/usr/share/lua/5.3/pgmoon/crypto.lua'
no file '/usr/share/lua/5.3/pgmoon/crypto/init.lua'
no file './pgmoon/crypto.lua'
no file './pgmoon/crypto/init.lua'
no file '/usr/local/lib/lua/5.3/pgmoon/crypto.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.3/pgmoon/crypto.so'
no file '/usr/lib/lua/5.3/pgmoon/crypto.so'
no file '/usr/local/lib/lua/5.3/loadall.so'
no file './pgmoon/crypto.so'
no file '/usr/local/lib/lua/5.3/pgmoon.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.3/pgmoon.so'
no file '/usr/lib/lua/5.3/pgmoon.so'
no file '/usr/local/lib/lua/5.3/loadall.so'
no file './pgmoon.so' from [C] global 'require', /usr/local/share/lua/5.3/pgmoon/init.lua:269 C function line 267 ..., /usr/local/share/lua/5.3/pgmoon/init.lua:211 method 'connect', /usr/local/haproxy/queue-request.lua:38 C function line 25.
however, there is a file at /usr/local/share/lua/5.3/pgmoon/crypto.lua, this is what ls shows:
# ls -la /usr/local/share/lua/5.3/pgmoon/
total 60
drwxr-xr-x 1 root root 4096 Mar 24 23:42 .
drwxr-xr-x 1 root root 4096 Mar 24 23:00 ..
-rw-r--r-- 1 root root 2880 Mar 24 23:00 arrays.lua
-rw-r--r-- 1 root root 1130 Mar 24 23:00 bit.lua
-rw-r--r-- 1 root root 1587 Mar 24 23:00 cqueues.lua
-rw-r--r-- 1 root root 654 Mar 24 23:00 crypto.lua
-rw-r--r-- 1 root root 2084 Mar 24 23:00 hstore.lua
-rw-r--r-- 1 root root 20127 Mar 24 23:00 init.lua
-rw-r--r-- 1 root root 665 Mar 24 23:00 json.lua
-rw-r--r-- 1 root root 2728 Mar 24 23:42 socket.lua
-rw-r--r-- 1 root root 457 Mar 24 23:00 util.lua
i could see it being permissions-related, if the haproxy user couldn't access a root owned file, but by the time it gets here it's already executed init.lua which has imported socket.lua and they've all got the same permissions...
Anybody know why lua thinks there is no file at crypto.lua?
I guess that you have haproxy configured with chroot and there actually isn't a file at /usr/local/share/lua/5.3/pgmoon/crypto.lua - in the chroot you haproxy runs in.
The require('pgmoon.crypto') in init.lua is within a function and probably tries to run long after Haproxy and lua initialization - and the root change.
And somewhat (un)relatedly - you can probably expect other problems with the pgmoon not being aware of haproxy, eg. its use of luasocket and not the haproxy-provided replacement: https://www.haproxy.com/blog/5-ways-to-extend-haproxy-with-lua/
The Socket class is a replacement for the standard Lua Socket class and is compatible with HAProxy’s non-blocking nature. When you want to use socket functions in your actions, you must use this class.

Xcode Unit Tests returns the NSURL of temp folder without 'private keyword'

I am writing Unit Tests in Objective C.
The following is my code:
NSString *testTempDirectory = [NSString stringWithFormat:#"%#%#", NSTemporaryDirectory(), #"DC_Tests"];
NSURL *parentDirURL = [NSURL fileURLWithPath:testTempDirectory];
NSURL *testFolderURL = [NSURL fileURLWithPath:testFolderPath];
Now the path in testFolderURL is returned as
/var/folders/31/2dpztnmx4fzfxb87qtn5_n0wc49pvz/T/DC_Tests/testFolder/
But the original path is
/private/var/folders/31/2dpztnmx4fzfxb87qtn5_n0wc49pvz/T/DC_Tests/testFolder/
The original path is my expected path and since it is different, my assertion is failing.
Any idea as to how do I get the complete path.
Note: I tried absolute string, doesn't help.
Note that in Mac OS, the var folder is actually a linked folder to /private/var
$ ls -l /
total 45
drwxrwxr-x+ 61 root admin 2074 Jun 11 08:58 Applications
drwxr-xr-x+ 63 root wheel 2142 Jul 6 2016 Library
drwxr-xr-x# 2 root wheel 68 Aug 24 2015 Network
drwxr-xr-x# 4 root wheel 136 Jun 9 18:56 System
drwxr-xr-x 6 root admin 204 Apr 22 2016 Users
drwxrwxrwt# 4 root admin 136 Jun 15 09:53 Volumes
drwxr-xr-x# 39 root wheel 1326 Jun 9 18:56 bin
drwxrwxr-t# 2 root admin 68 Aug 24 2015 cores
dr-xr-xr-x 3 root wheel 4312 Jun 9 18:57 dev
lrwxr-xr-x# 1 root wheel 11 Oct 18 2015 etc -> private/etc
dr-xr-xr-x 2 root wheel 1 Jun 9 18:58 home
-rw-r--r--# 1 root wheel 313 Aug 23 2015 installer.failurerequests
dr-xr-xr-x 2 root wheel 1 Jun 9 18:58 net
drwxr-xr-x# 6 root wheel 204 Oct 18 2015 private
drwxr-xr-x# 59 root wheel 2006 Jun 9 18:56 sbin
lrwxr-xr-x# 1 root wheel 11 Oct 18 2015 tmp -> private/tmp
drwxr-xr-x# 13 root wheel 442 Apr 19 2016 usr
lrwxr-xr-x# 1 root wheel 11 Oct 18 2015 var -> private/var
So the simplest way to fix your test is to ignore the /private part from the path. (We had a similar issue with paths that contain the tmp folder on Mac OS as well)

Haproxy can load socket.http.module 'socket.http' not found

i already install luasocket
Lua 5.3.1 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> require("socket.http")
table: 0x9b2d80
>
debian:/usr/local/share/lua/5.3/socket# ll
total 56
-rw-r--r-- 1 root root 10640 Dec 22 17:47 ftp.lua
-rw-r--r-- 1 root root 3698 Dec 22 17:47 headers.lua
-rw-r--r-- 1 root root 13216 Dec 22 17:47 http.lua
-rw-r--r-- 1 root root 8074 Dec 22 17:47 smtp.lua
-rw-r--r-- 1 root root 3766 Dec 22 17:47 tp.lua
-rw-r--r-- 1 root root 11105 Dec 22 17:47 url.lua
in Haproxy Lua code:
local http = require("socket.http")
When i request web,
runtime error: /etc/haproxy/waf/lib.lua:7: module 'socket.http' not found:#012#011no field package.preload['socket.http']#012#011no file '/usr/local/share/lua/5.3/socket/http.lua'#012#011no file '/usr/local/share/lua/5.3/socket/http/init.lua'#012#011no file '/usr/local/lib/lua/5.3/socket/http.lua'#012#011no file '/usr/local/lib/lua/5.3/socket/http/init.lua'#012#011no file '/usr/share/lua/5.3/socket/http.lua'#012#011no file '/usr/share/lua/5.3/socket/http/init.lua'#012#011no file './socket/http.lua'#012#011no file './socket/http/init.lua'#012#011no file '/etc/haproxy/waf/socket/http.lua'#012#011no file '/etc/haproxy/waf/socket/http.lua'#012#011no file '/usr/local/lib/lua/5.3/socket/http.so'#012#011no file '/usr/lib/x86_64-linux-gnu/lua/5.3/socket/http.so'#012#011no file '/usr/lib/lua/5.3/socket/http.so'#012#011no file '/usr/local/lib/lua/5.3/loadall.so'#012#011no file './socket/http.so'#012#011no file '/usr/local/lib/lua/5.3/socket.so'#012#011no file '/usr/lib/x86_64-linux-gnu/lua/5.3/socket.so'#012#011no file '/usr/lib/lua/5.3/socket.so'#012#011no file '/usr/lo
who can help me. thx
Your computer cannot find the required files.
https://www.lua.org/pil/8.1.html
To determine its path, require first checks the global variable
LUA_PATH. If the value of LUA_PATH is a string, that string is the
path. Otherwise, require checks the environment variable LUA_PATH.
Finally, if both checks fail, require uses a fixed path (typically
"?;?.lua", although it is easy to change that when you compile Lua).
The content of LUA_PATH will be copied into package.path. So either add the location of that module to the system variable befor running Lua or add it to package.path befor require.

idlj parameter invalid argument -td mac?

Im trying to follow a tutorial to do a CORBA assignment.
project
-Client/HelloClient.java
-Server/HelloServer.java
-Hello.idl
I do the first step, trying to compile the IDL (from the project root), and it fails.
$ idlj –td Client –fclient Hello.idl
com.sun.tools.corba.se.idl.InvalidArgument: Invalid argument: –td.
java version "1.8.0_11"
$ ls -l
total 16
drwxr-xr-x 3 juliusskye staff 102 Oct 28 20:14 Client
-rw-r-----# 1 juliusskye staff 85 Oct 28 17:49 Hello.idl
drwxr-xr-x 3 juliusskye staff 102 Oct 28 17:52 Server
-rw-r--r-- 1 juliusskye staff 425 Oct 29 13:45 idljintro.iml
drwxr-xr-x 2 juliusskye staff 68 Oct 29 13:45 src
I found this which says CORBA has problems parsing paths with / in front. But mine doesn't have a /
apparently the Lecturer's instructions were wrong or outdated or the compiler is not fully working but compilation of all files is achieved by
idlj -fall hello.idl

Resources