-
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.
Merge pull request #1366 from Mashape/refactor/restart
feature: restart and health
- Loading branch information
Showing
16 changed files
with
386 additions
and
40 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,55 @@ | ||
local log = require "kong.cmd.utils.log" | ||
local kill = require "kong.cmd.utils.kill" | ||
local pl_path = require "pl.path" | ||
local pl_tablex = require "pl.tablex" | ||
local pl_stringx = require "pl.stringx" | ||
local conf_loader = require "kong.conf_loader" | ||
|
||
local function execute(args) | ||
-- retrieve default 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) | ||
assert(pl_path.exists(default_conf.kong_conf), | ||
"Kong is not running at "..default_conf.prefix) | ||
|
||
-- load <PREFIX>/kong.conf containing running node's config | ||
local conf = assert(conf_loader(default_conf.kong_conf)) | ||
|
||
local pids = { | ||
serf = conf.serf_pid, | ||
nginx = conf.nginx_pid, | ||
dnsmasq = conf.dnsmasq and conf.dnsmasq_pid or nil | ||
} | ||
|
||
local count = 0 | ||
for k, v in pairs(pids) do | ||
local running = kill.is_running(v) | ||
local msg = pl_stringx.ljust(k, 12, ".")..(running and "running" or "not running") | ||
if running then | ||
count = count + 1 | ||
end | ||
log(msg) | ||
end | ||
|
||
log("") -- line jump | ||
|
||
assert(count > 0, "Kong is not running at "..conf.prefix) | ||
assert(count == pl_tablex.size(pids), "Some services are not running at "..conf.prefix) | ||
|
||
log("Kong is healthy at %s", conf.prefix) | ||
end | ||
|
||
local lapp = [[ | ||
Usage: kong health [OPTIONS] | ||
Options: | ||
-p,--prefix (optional string) prefix at which Kong should be running | ||
]] | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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 kill = require "kong.cmd.utils.kill" | ||
local log = require "kong.cmd.utils.log" | ||
|
||
local function execute(args) | ||
-- retrieve default 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)) | ||
|
||
-- try graceful shutdown (QUIT) | ||
assert(nginx_signals.quit(conf)) | ||
|
||
log.verbose("waiting for Nginx to finish processing requests...") | ||
|
||
local tstart = ngx.time() | ||
local texp, running = tstart + math.max(args.timeout, 1) -- min 1s timeout | ||
repeat | ||
ngx.sleep(0.2) | ||
running = kill.is_running(conf.nginx_pid) | ||
until not running or ngx.time() >= texp | ||
|
||
if running then | ||
log.verbose("Nginx is still running at %s, forcing shutdown", conf.prefix) | ||
assert(nginx_signals.stop(conf)) | ||
end | ||
|
||
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: | ||
-p,--prefix (optional string) prefix Kong is running at | ||
-t,--timeout (default 10) timeout before forced shutdown | ||
]] | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local stop = require "kong.cmd.stop" | ||
local start = require "kong.cmd.start" | ||
local conf_loader = require "kong.conf_loader" | ||
|
||
local function execute(args) | ||
if args.conf then | ||
-- retrieve the prefix for stop | ||
local conf = assert(conf_loader(args.conf)) | ||
args.prefix = conf.prefix | ||
end | ||
|
||
pcall(stop.execute, args) | ||
start.execute(args) | ||
end | ||
|
||
local lapp = [[ | ||
Usage: kong restart [OPTIONS] | ||
Options: | ||
-c,--conf (optional string) configuration file | ||
-p,--prefix (optional string) prefix at which Kong should be running | ||
]] | ||
|
||
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
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
Oops, something went wrong.