File tree Expand file tree Collapse file tree 2 files changed +12
-17
lines changed Expand file tree Collapse file tree 2 files changed +12
-17
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ idea is that the shell library connects to the unix domain socket of sockproc da
11
11
sends the command along with any input data that the child program is expecting, and then
12
12
reads back the exit code, output stream data, and error stream data of
13
13
the child process. Because we use co-socket API, provided by
14
- [ lua-nginx-module] ( https://github.com/chaoslawful /lua-nginx-module ) ,
14
+ [ lua-nginx-module] ( https://github.com/openresty /lua-nginx-module ) ,
15
15
the nginx worker is never blocked.
16
16
17
17
More info on sockproc server, including complete source code here:
@@ -30,7 +30,6 @@ In your OpenResty config:
30
30
content_by_lua '
31
31
local shell = require("resty.shell")
32
32
33
-
34
33
-- define a table to hold arguments with the following elements:
35
34
--
36
35
-- timeout: timeout for the socket connection
Original file line number Diff line number Diff line change @@ -9,34 +9,30 @@ local tonumber = tonumber
9
9
10
10
11
11
local shell = {
12
- _VERSION = ' 0.01 '
12
+ _VERSION = ' 0.02 '
13
13
}
14
14
15
15
local default_socket = " unix:/tmp/shell.sock"
16
16
17
+
17
18
function shell .execute (cmd , args )
18
19
local timeout = args and args .timeout
19
20
local input_data = args and args .data or " "
20
21
local socket = args and args .socket or default_socket
21
22
22
23
local is_tcp
23
-
24
- if (type (socket ) == ' table' ) then
25
- if (socket .host and socket .port ) then
26
- is_tcp = true
27
- else
28
- return - 3 , nil , ' invalid socket table options passed'
29
- end
30
- elseif (type (socket ) == ' string' ) then
31
- is_tcp = false
32
- else
33
- return - 3 , nil , ' socket was not a table with tcp options or a string'
34
- end
24
+ if type (socket ) == ' table' then
25
+ if socket .host and tonumber (socket .port ) then
26
+ is_tcp = true
27
+ else
28
+ error (' socket table must have host and port keys' )
29
+ end
30
+ end
35
31
36
32
local sock = tcp ()
37
33
local ok , err
38
- if ( is_tcp ) then
39
- ok , err = sock :connect (socket .host , socket .port )
34
+ if is_tcp then
35
+ ok , err = sock :connect (socket .host , tonumber ( socket .port ) )
40
36
else
41
37
ok , err = sock :connect (socket )
42
38
end
You can’t perform that action at this time.
0 commit comments