Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli) better version information for dependency binaries #1307

Merged
merged 2 commits into from Jul 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions kong-0.8.2-0.rockspec
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
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
@@ -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