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

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.

Related

What does "dot slash dot" (./.) mean in a Nix expression?

Wherever I see flake-compat used, it is a variation of
(import (fetchTarball https://github.com/edolstra/flake-compat/archive/master.tar.gz) {
src = ./.;
}).shellNix
It is obviously a path that refers to the current directory which can be proven with a simple test:
[~/testdir]$ ll .
total 24
drwxr-xr-x 2 toraritte users 4096 Jul 21 21:56 ./
drwx------ 7 toraritte users 20480 Jul 15 23:13 ../
-rw-r--r-- 1 toraritte users 0 Jul 21 21:56 lofa
[~/testdir]$ ll ./.
total 24
drwxr-xr-x 2 toraritte users 4096 Jul 21 21:56 ./
drwx------ 7 toraritte users 20480 Jul 15 23:13 ../
-rw-r--r-- 1 toraritte users 0 Jul 21 21:56 lofa
So why not simply use .?
From 5.2.1 Values section of the Nix manual (emphasis mine):
Paths, e.g., /bin/sh or ./builder.sh. A path must contain at least one
slash to be recognised as such.
For instance, builder.sh is not a
path: it's parsed as an expression that selects the attribute sh from
the variable builder. If the file name is relative, i.e., if it does
not begin with a slash, it is made absolute at parse time relative to
the directory of the Nix expression that contained it. For instance,
if a Nix expression in /foo/bar/bla.nix refers to ../xyzzy/fnord.nix,
the absolute path is /foo/xyzzy/fnord.nix.

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.

Jenkins can't find artifacts

I have a jenkins running a job, after which I want it to "archive artifact", which is basically just get some files.
The Job clones a github and when ran, it generates some log files which I need.
The patter is:
logfiles/*
I added a command to list the directory to make sure the files are there, and indeed they are.
+ ls -la logfiles
total 24
drwxr-xr-x 2 root root 4096 Apr 22 23:23 .
drwxr-xr-x 8 root root 4096 Apr 22 23:23 ..
-rw-r--r-- 1 root root 0 Apr 22 23:23 1461367410777_testuuid_61746144-3A3A-5555-4944-3D5343414C41.log
-rw-r--r-- 1 root root 1248 Apr 22 23:23 1461367410777_testuuid_61746144-3A3A-5555-4944-3D5343414C41_shortmsg.csv
-rw-r--r-- 1 root root 2521 Apr 22 23:23 1461367410777_testuuid_61746144-3A3A-5555-4944-3D5343414C41_stats.log
-rw-r--r-- 1 root root 8035 Apr 22 23:23 1461367410777_testuuid_61746144-3A3A-5555-4944-3D5343414C41_trace_msg.log
Archiving artifacts
ERROR: No artifacts found that match the file pattern "logfiles/*". Configuration error?
ERROR: ‘logfiles/*’ doesn’t match anything, but ‘*’ does. Perhaps that’s what you mean?
Build step 'Archive the artifacts' changed build result to FAILURE
I don't really understand why they are not found.
Hope someone can help!
Thanks!
I finally found my problem. I had configured the job to do the git clone. But for some reason I also added the cloning on the build steps... once i removed that jenkins started getting the files properly.
I would still like to understand why this would happen...
Thanks to all

Rails 4 SQLite3::ReadOnlyException: attempt to write a readonly database

I keep receiving the error SQLite3::ReadOnlyException: attempt to write a readonly database: UPDATE "users" SET "current_sign_in_at" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = ? when trying to sign into my Rails 4 app which uses the devise gem.
I figured it has something to do with permissions on the dev db so checked out the permissions of the dir first, it has a + tacked onto the end which after some googling still couldn't figure out what it's doing.
-rw-r--r-- 1 a36971 staff 2.1K 24 Jan 20:16 Gemfile
-rw-r--r-- 1 a36971 staff 5.7K 24 Jan 20:16 Gemfile.lock
-rw-r--r-- 1 a36971 staff 47B 7 Jan 22:31 README.md
-rw-r--r--+ 1 root staff 249B 7 Jan 19:57 Rakefile
drwxr-xr-x+ 8 root staff 272B 7 Jan 19:57 app/
drwxr-xr-x+ 7 root staff 238B 7 Jan 19:57 bin/
drwxr-xr-x+ 13 root staff 442B 22 Jan 20:14 config/
-rw-r--r--+ 1 root staff 153B 7 Jan 19:57 config.ru
drwxr-xr-x+ 8 root staff 272B 26 Jan 10:28 db/
drwxr-xr-x+ 4 root staff 136B 7 Jan 19:57 lib/
drwxr-xr-x+ 5 root staff 170B 8 Jan 15:51 log/
drwxr-xr-x+ 7 root staff 238B 7 Jan 19:57 public/
drwxr-xr-x 7 a36971 staff 238B 17 Jan 22:38 spec/
drwxr-xr-x+ 9 root staff 306B 7 Jan 19:57 test/
drwxr-xr-x+ 6 root staff 204B 7 Jan 20:19 tmp/
drwxr-xr-x+ 3 root staff 102B 7 Jan 19:57 vendor/
After cd ing into the db dir you can see there's nothing wrong with the permissions on the db itself:
-rw-r--r-- 1 a36971 staff 44K 26 Jan 09:30 development.sqlite3
drwxr-xr-x 5 a36971 staff 170B 22 Jan 20:14 migrate/
-rw-r--r-- 1 a36971 staff 2.2K 22 Jan 20:14 schema.rb
-rw-r--r-- 1 a36971 staff 1.2K 25 Jan 23:22 seeds.rb
-rw-r--r-- 1 a36971 staff 44K 26 Jan 09:23 test.sqlite3
So my questions are:
a) why is it unable to write to the db when there doesn't appear to be anything wrong with the permissions themselves
b) what does the + mean on mac os?
a) why is it unable to write to the db when there doesn't appear to be anything wrong with the permissions themselves
My best guess is that the db/ directory is owned by the root user, whereas the db/*.sqlite3 files are owned by user a36971. It may be necessary for the db/ directory to also be owned by user a36971.
Try changing the owner from root to a36971 for the db directory:
sudo chown a36971 db
b) what does the + mean on mac os?
+ sign means there are additional permission details not displayed by the default output from ls -l. Try running ls -le to see the details (source: http://tech.enekochan.com/en/2014/05/29/plus-and-at-symbols-listing-file-permissions-in-mac-os-x/).
Got the same error after running rails db:reset
Restarting the local server fixed my problem

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