|
37 | 37 | -- @param path_to_check Path to the binary
|
38 | 38 | -- @return true or false
|
39 | 39 | local function is_openresty(path_to_check)
|
40 |
| - if IO.file_exists(path_to_check) then |
41 |
| - local cmd = path_to_check.." -v" |
42 |
| - local out, code = IO.os_execute(cmd) |
43 |
| - if code ~= 0 then |
44 |
| - cutils.logger:error_exit(out) |
45 |
| - end |
46 |
| - return out:match("^nginx version: ngx_openresty/") |
47 |
| - or out:match("^nginx version: openresty/") |
48 |
| - or out:match("^nginx version: nginx/[%w.%s]+%(nginx%-plus%-extras.+%)") |
49 |
| - end |
50 |
| - return false |
| 40 | + local cmd = path_to_check.." -v" |
| 41 | + local out = IO.os_execute(cmd) |
| 42 | + return out:match("^nginx version: ngx_openresty/") |
| 43 | + or out:match("^nginx version: openresty/") |
| 44 | + or out:match("^nginx version: nginx/[%w.%s]+%(nginx%-plus%-extras.+%)") |
51 | 45 | end
|
52 | 46 |
|
53 |
| --- Paths where to search for an `nginx` executable in addition to the usual $PATH |
| 47 | +-- Preferred paths where to search for an `nginx` executable in priority to the $PATH |
54 | 48 | local NGINX_BIN = "nginx"
|
55 | 49 | local NGINX_SEARCH_PATHS = {
|
56 | 50 | "/usr/local/openresty/nginx/sbin/",
|
57 | 51 | "/usr/local/opt/openresty/bin/",
|
58 | 52 | "/usr/local/bin/",
|
59 |
| - "/usr/sbin/" |
| 53 | + "/usr/sbin/", |
| 54 | + "" -- to check the $PATH |
60 | 55 | }
|
61 | 56 |
|
62 | 57 | -- Try to find an `nginx` executable in defined paths, or in $PATH
|
63 | 58 | -- @return Path to found executable or nil if none was found
|
64 | 59 | local function find_nginx()
|
65 |
| - for i = 1, #NGINX_SEARCH_PATHS + 1 do |
66 |
| - local prefix = NGINX_SEARCH_PATHS[i] and NGINX_SEARCH_PATHS[i] or "" |
| 60 | + for i = 1, #NGINX_SEARCH_PATHS do |
| 61 | + local prefix = NGINX_SEARCH_PATHS[i] |
67 | 62 | local to_check = prefix..NGINX_BIN
|
68 | 63 | if is_openresty(to_check) then
|
69 | 64 | return to_check
|
|
0 commit comments