Skip to content

Commit

Permalink
feat(cli) better version information for dependency binaries (#1307)
Browse files Browse the repository at this point in the history
* add better version information, replaces PR #1221
  • Loading branch information
Tieske authored Jul 1, 2016
1 parent ed2c248 commit e1c4ab3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions kong-0.8.2-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies = {
"lbase64 ~> 20120820-1",
"lua-resty-iputils ~> 0.2.0-1",
"mediator_lua ~> 1.1.2-0",
"version == 0.2",

"luasocket ~> 2.0.2-6",
"lrexlib-pcre ~> 2.7.2-1",
Expand Down
23 changes: 16 additions & 7 deletions kong/cmd/utils/nginx_signals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@ local pl_utils = require "pl.utils"
local pl_path = require "pl.path"
local kill = require "kong.cmd.utils.kill"
local log = require "kong.cmd.utils.log"
local version = require "version"
local fmt = string.format

local nginx_bin_name = "nginx"
local nginx_search_paths = {
"/usr/local/openresty/nginx/sbin",
""
}

local nginx_version_command = "-v" -- commandline param to get version
local nginx_version_pattern = "^nginx.-openresty.-([%d%.]+)" -- pattern to grab version from output
local nginx_compatible = version.set("1.9.3.2","1.9.7.4") -- compatible from-to versions

local function is_openresty(bin_path)
local cmd = fmt("%s -v", bin_path)
local ok, _, _, v_str = pl_utils.executeex(cmd)
if ok and v_str then
log.debug("%s: '%s'", cmd, v_str:sub(1, -2))
return v_str:match "^nginx version: ngx_openresty/" or
v_str:match "^nginx version: openresty/"
local cmd = fmt("%s %s", bin_path, nginx_version_command)
local ok, _, _, stderr = pl_utils.executeex(cmd)
if ok and stderr then
log.debug("%s: '%s'", cmd, stderr:sub(1, -2))
local version_match = stderr:match(nginx_version_pattern)
if (not version_match) or (not nginx_compatible:matches(version_match)) then
return nil, "incompatible nginx found. Kong requires OpenResty, version "..tostring(nginx_compatible) ..
(version_match and ", got "..version_match or "")
end
return true
end
return nil, "could not determine nginx version in use. Kong requires OpenResty version "..tostring(nginx_compatible)
end

local function send_signal(pid_path, signal)
Expand Down
15 changes: 11 additions & 4 deletions kong/cmd/utils/serf_signals.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced implementation of previous "services.serf.lua" module,
-- no change in acutal logic, only decoupled from the events features
-- no change in actual logic, only decoupled from the events features
-- which now live in kong.serf

local pl_stringx = require "pl.stringx"
Expand All @@ -9,17 +9,24 @@ local pl_file = require "pl.file"
local Serf = require "kong.serf"
local kill = require "kong.cmd.utils.kill"
local log = require "kong.cmd.utils.log"
local version = require "version"
local fmt = string.format

local serf_bin_name = "serf"
local serf_event_name = "kong"
local serf_version_command = " version" -- commandline param to get version
local serf_version_pattern = "^Serf v([%d%.]+)" -- pattern to grab version from output
local serf_compatible = version.set("0.7.0", "0.7.0") -- compatible from-to versions
local start_timeout = 5

local function check_serf_bin()
local cmd = string.format("%s -v", serf_bin_name)
local cmd = fmt("%s %s", serf_bin_name, serf_version_command)
local ok, _, stdout = pl_utils.executeex(cmd)
if ok and stdout then
if not stdout:match "^Serf v0%.7%.0" then
return nil, "wrong Serf version (need 0.7.0)"
local version_match = stdout:match(serf_version_pattern)
if (not version_match) or (not serf_compatible:matches(version_match)) then
return nil, "incompatible Serf version. Kong requires version "..tostring(serf_compatible)..
(version_match and ", got "..tostring(version_match) or "")
end
return true
end
Expand Down

0 comments on commit e1c4ab3

Please sign in to comment.