-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feature: restart and health #1366
Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f0f61b0
restart
subnetmarco 2c3710d
health
subnetmarco 6c2820c
refactor
subnetmarco cef1baa
feat(cli) kong health + restart commands
subnetmarco c55c981
refactor(cli) better health/restart impl + tests
thibaultcha de03293
kong quit and tests
subnetmarco fcf7470
quit and tests
subnetmarco 3cd3ece
better assert.matches
subnetmarco 80906ce
fix(cli) health command only accepts --prefix arg
thibaultcha ccea6d3
feat(cli) implement 'kong quit' with --timeout
thibaultcha 7217798
restart
subnetmarco 30bb41c
health
subnetmarco e8cb830
refactor
subnetmarco c566b76
refactor(cli) better health/restart impl + tests
thibaultcha 6e00b81
kong quit and tests
subnetmarco 5d35ee2
better assert.matches
subnetmarco 82f52d6
Merge branch 'proper-stop' into refactor/restart
thibaultcha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,37 @@ | ||
local dnsmasq_signals = require "kong.cmd.utils.dnsmasq_signals" | ||
local nginx_signals = require "kong.cmd.utils.nginx_signals" | ||
local serf_signals = require "kong.cmd.utils.serf_signals" | ||
local conf_loader = require "kong.conf_loader" | ||
local DAOFactory = require "kong.dao.factory" | ||
local pl_path = require "pl.path" | ||
local log = require "kong.cmd.utils.log" | ||
|
||
local function execute(args) | ||
-- retrieve prefix or use given one | ||
local default_conf = assert(conf_loader(nil, { | ||
prefix = args.prefix | ||
})) | ||
assert(pl_path.exists(default_conf.prefix), | ||
"no such prefix: "..default_conf.prefix) | ||
|
||
-- load <PREFIX>/kong.conf containing running node's config | ||
local conf = assert(conf_loader(default_conf.kong_conf)) | ||
assert(nginx_signals.stop(conf, true)) | ||
assert(serf_signals.stop(conf, DAOFactory(conf))) | ||
if conf.dnsmasq then | ||
assert(dnsmasq_signals.stop(conf)) | ||
end | ||
log("Stopped gracefully") | ||
end | ||
|
||
local lapp = [[ | ||
Usage: kong quit [OPTIONS] | ||
|
||
Options: | ||
--prefix (optional string) prefix Kong is running at | ||
]] | ||
|
||
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 |
---|---|---|
@@ -1,9 +1,55 @@ | ||
local helpers = require "spec.helpers" | ||
|
||
describe("kong cluster", function() | ||
it("keygen", function() | ||
local _, stderr, stdout = helpers.kong_exec "cluster keygen" | ||
before_each(function() | ||
helpers.kill_all() | ||
end) | ||
teardown(function() | ||
helpers.kill_all() | ||
helpers.clean_prefix() | ||
end) | ||
|
||
|
||
it("cluster help", function() | ||
local _, stderr = helpers.kong_exec "cluster --help" | ||
assert.not_equal("", stderr) | ||
end) | ||
it("generates a key", function() | ||
local _, stderr, stdout = assert(helpers.kong_exec("cluster keygen")) | ||
assert.equal("", stderr) | ||
assert.equal(26, stdout:len()) -- 24 + \r\n | ||
end) | ||
it("shows members", function() | ||
assert(helpers.kong_exec("start --conf "..helpers.test_conf_path)) | ||
local _, _, stdout = assert(helpers.kong_exec("cluster members --conf "..helpers.test_conf_path)) | ||
assert.matches("alive", stdout) | ||
end) | ||
it("shows rechability", function() | ||
assert(helpers.kong_exec("start --conf "..helpers.test_conf_path)) | ||
local _, _, stdout = assert(helpers.kong_exec("cluster reachability --conf "..helpers.test_conf_path)) | ||
assert.matches("Successfully contacted all live nodes", stdout) | ||
end) | ||
it("force-leaves a node", function() | ||
assert(helpers.kong_exec("start --conf "..helpers.test_conf_path)) | ||
local _, _, stdout = assert(helpers.kong_exec("cluster force-leave 127.0.0.1 --conf "..helpers.test_conf_path)) | ||
assert.matches("left node 127.0.0.1", stdout) | ||
end) | ||
|
||
describe("errors", function() | ||
it("fails to show members when Kong is not running", function() | ||
local ok, stderr = helpers.kong_exec("cluster members --conf "..helpers.test_conf_path) | ||
assert.False(ok) | ||
assert.matches("Error connecting to Serf agent", stderr) | ||
end) | ||
it("fails to show reachability when Kong is not running", function() | ||
local ok, stderr = helpers.kong_exec("cluster reachability --conf "..helpers.test_conf_path) | ||
assert.False(ok) | ||
assert.matches("Error connecting to Serf agent", stderr) | ||
end) | ||
it("fails to force-leave when a node is not specified", function() | ||
local ok, stderr = helpers.kong_exec("cluster force-leave --conf "..helpers.test_conf_path) | ||
assert.False(ok) | ||
assert.matches("must specify the name of the node to leave", stderr) | ||
end) | ||
end) | ||
end) |
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,21 @@ | ||
local helpers = require "spec.helpers" | ||
|
||
describe("kong start/stop", function() | ||
teardown(function() | ||
helpers.kill_all() | ||
helpers.clean_prefix() | ||
end) | ||
before_each(function() | ||
helpers.kill_all() | ||
end) | ||
|
||
it("quit help", function() | ||
local _, stderr = helpers.kong_exec "quit --help" | ||
assert.not_equal("", stderr) | ||
end) | ||
it("quits gracefully", function() | ||
assert(helpers.kong_exec("start --conf "..helpers.test_conf_path)) | ||
assert(helpers.kong_exec("quit --prefix "..helpers.test_conf.prefix)) | ||
end) | ||
|
||
end) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
Because arg #1 will be interpreted as a pattern otherwise, which means
.
can be any character. Better to have sane examples to not lead to errors in the future.