Skip to content

Commit

Permalink
fix(cli) properly look for serf in known paths (Kong#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco authored and Tieske committed Feb 7, 2017
1 parent c192634 commit 64f5e9b
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions kong/cmd/utils/serf_signals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,46 @@ local serf_event_name = "kong"
local serf_version_pattern = "^Serf v([%d%.]+)"
local serf_compatible = version.set(unpack(meta._DEPENDENCIES.serf))
local start_timeout = 5
local serf_search_paths = {
"serf",
"/usr/local/bin/serf"
}

local function check_serf_bin(kong_config)
log.debug("checking 'serf' executable from 'serf_path' config setting")

local cmd = fmt("%s version", kong_config.serf_path)
local function check_version(path)
local cmd = fmt("%s version", path)
local ok, _, stdout = pl_utils.executeex(cmd)
log.debug("%s: '%s'", cmd, pl_stringx.splitlines(stdout)[1])
if ok and stdout then
local version_match = stdout:match(serf_version_pattern)
if not version_match or not serf_compatible:matches(version_match) then
return nil, "incompatible serf found. Kong requires version "..
tostring(serf_compatible)..", got "..version_match
return nil, fmt("incompatible serf found at '%s'. Kong requires version '%s', got '%s'",
path, tostring(serf_compatible), version_match)
end
return true
end
end

local function check_serf_bin(kong_config)
log.debug("searching for 'serf' executable")

if kong_config.serf_path then
serf_search_paths = { kong_config.serf_path }
end

local found
for _, path in ipairs(serf_search_paths) do
if check_version(path) then
found = path
log.debug("found 'serf' executable at %s", found)
break
end
end

if not found then
return nil, "could not find 'serf' executable (is 'serf_path' correctly set?)"
end

return nil, "could not find 'serf' executable (is 'serf_path' correctly set?)"
return found
end

local _M = {}
Expand Down

0 comments on commit 64f5e9b

Please sign in to comment.