Skip to content

Commit

Permalink
feat(conf) add openresty_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
flrgh committed Feb 17, 2022
1 parent cb1c4da commit c713bfa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
11 changes: 11 additions & 0 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -1544,3 +1544,14 @@
# **Warning**: Certain variables, when made
# available, may create opportunities to
# escape the sandbox.

#openresty_prefix = # Path to the OpenResty installation that Kong
# will use. When this is empty (the default),
# Kong determines the OpenResty installation
# by searching for a system-installed OpenResty
# and falling back to searching $PATH for the
# nginx binary.
#
# Setting this attribute disables the search
# behavior and explicitly instructs Kong which
# OpenResty installation to use.
40 changes: 19 additions & 21 deletions kong/cmd/utils/nginx_signals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,12 @@ local pl_stringx = require "pl.stringx"
local fmt = string.format

local nginx_bin_name = "nginx"
local nginx_search_paths
do
local resty_prefix = os.getenv("KONG_OPENRESTY_PREFIX")
if resty_prefix then
log.debug("using custom OpenResty prefix: %s", resty_prefix)
nginx_search_paths = {
pl_path.join(resty_prefix, "nginx", "sbin")
}
else
nginx_search_paths = {
"/usr/local/openresty/nginx/sbin",
"/opt/openresty/nginx/sbin",
""
}
end
end
local nginx_search_paths = {
"/usr/local/openresty/nginx/sbin",
"/opt/openresty/nginx/sbin",
""
}

local nginx_version_pattern = "^nginx.-openresty.-([%d%.]+)"
local nginx_compatible = version.set(unpack(meta._DEPENDENCIES.nginx))

Expand Down Expand Up @@ -61,11 +51,19 @@ end

local _M = {}

function _M.find_nginx_bin()
function _M.find_nginx_bin(kong_conf)
log.debug("searching for OpenResty 'nginx' executable")

local search_paths = nginx_search_paths
if kong_conf and kong_conf.openresty_prefix then
log.debug("using custom OpenResty prefix: %s", kong_conf.openresty_prefix)
search_paths = {
pl_path.join(kong_conf.openresty_prefix, "nginx", "sbin"),
}
end

local found
for _, path in ipairs(nginx_search_paths) do
for _, path in ipairs(search_paths) do
local path_to_check = pl_path.join(path, nginx_bin_name)
if is_openresty(path_to_check) then
if path_to_check == "nginx" then
Expand Down Expand Up @@ -94,7 +92,7 @@ function _M.find_nginx_bin()
end

function _M.start(kong_conf)
local nginx_bin, err = _M.find_nginx_bin()
local nginx_bin, err = _M.find_nginx_bin(kong_conf)
if not nginx_bin then
return nil, err
end
Expand Down Expand Up @@ -131,7 +129,7 @@ function _M.start(kong_conf)
end

function _M.check_conf(kong_conf)
local nginx_bin, err = _M.find_nginx_bin()
local nginx_bin, err = _M.find_nginx_bin(kong_conf)
if not nginx_bin then
return nil, err
end
Expand Down Expand Up @@ -163,7 +161,7 @@ function _M.reload(kong_conf)
return nil, "nginx not running in prefix: " .. kong_conf.prefix
end

local nginx_bin, err = _M.find_nginx_bin()
local nginx_bin, err = _M.find_nginx_bin(kong_conf)
if not nginx_bin then
return nil, err
end
Expand Down
2 changes: 2 additions & 0 deletions kong/templates/kong_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,6 @@ pluginserver_names = NONE
untrusted_lua = sandbox
untrusted_lua_sandbox_requires =
untrusted_lua_sandbox_environment =
openresty_prefix =
]]

0 comments on commit c713bfa

Please sign in to comment.