-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0f61b0
commit 2c3710d
Showing
5 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
local conf_loader = require "kong.conf_loader" | ||
local log = require "kong.cmd.utils.log" | ||
local kill = require "kong.cmd.utils.kill" | ||
local pl_stringx = require "pl.stringx" | ||
local pl_path = require "pl.path" | ||
local pl_tablex = require "pl.tablex" | ||
|
||
local function is_running(pid_path) | ||
if not pl_path.exists(pid_path) then return nil end | ||
local code = kill(pid_path, "-0") | ||
return code == 0 | ||
end | ||
|
||
local function execute(args) | ||
local default_conf = assert(conf_loader(args.conf, { | ||
prefix = args.prefix | ||
})) | ||
assert(pl_path.exists(default_conf.prefix), | ||
"no such prefix: "..default_conf.prefix) | ||
|
||
local pids = { | ||
nginx = default_conf.nginx_pid, | ||
serf = default_conf.serf_pid, | ||
dnsmasq = default_conf.dnsmasq and default_conf.dnsmasq_pid or nil | ||
} | ||
|
||
local count = 0 | ||
for k, v in pairs(pids) do | ||
local running = is_running(v) | ||
local msg = pl_stringx.ljust(k, 10, ".")..(running and "running" or "not running") | ||
if running then | ||
count = count + 1 | ||
log(msg) | ||
else | ||
log.warn(msg) | ||
end | ||
end | ||
|
||
assert(count > 0, "Kong is not running") | ||
assert(count == pl_tablex.size(pids), "Some services are not running") | ||
end | ||
|
||
local lapp = [[ | ||
Usage: kong health [OPTIONS] | ||
Options: | ||
-c,--conf (optional string) configuration file | ||
--prefix (optional string) override prefix directory | ||
]] | ||
|
||
return { | ||
lapp = lapp, | ||
execute = execute | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
local helpers = require "spec.helpers" | ||
local prefix_handler = require "kong.cmd.utils.prefix_handler" | ||
|
||
describe("kong restart", function() | ||
before_each(function() | ||
helpers.kill_all() | ||
end) | ||
teardown(function() | ||
helpers.kill_all() | ||
helpers.clean_prefix() | ||
end) | ||
|
||
it("succeeds when Kong is running", function() | ||
assert(helpers.kong_exec("start --conf "..helpers.test_conf_path, {dnsmasq = true, dns_resolver = ""})) | ||
assert(helpers.kong_exec("health --conf "..helpers.test_conf_path)) | ||
end) | ||
|
||
describe("errors", function() | ||
it("fails when Kong is not running", function() | ||
assert(prefix_handler.prepare_prefix(helpers.test_conf)) | ||
local ok, stderr = helpers.kong_exec("health --conf "..helpers.test_conf_path) | ||
assert.False(ok) | ||
assert.matches("Kong is not running", stderr) | ||
end) | ||
it("fails when a service is not running", function() | ||
assert(helpers.kong_exec("start --conf "..helpers.test_conf_path, {dnsmasq = true, dns_resolver = ""})) | ||
helpers.execute("pkill serf") | ||
local ok, stderr = helpers.kong_exec("health --conf "..helpers.test_conf_path) | ||
assert.False(ok) | ||
assert.matches("Some services are not running", stderr) | ||
end) | ||
end) | ||
end) |