-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refactor/ssl-autogen' into refactor/cli
- Loading branch information
Showing
70 changed files
with
6,710 additions
and
3,983 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,51 @@ | ||
local conf_loader = require "kong.conf_loader" | ||
local DAOFactory = require "kong.dao.factory" | ||
local Serf = require "kong.serf" | ||
local log = require "kong.cmd.utils.log" | ||
|
||
local function execute(args) | ||
local conf = assert(conf_loader(args.conf)) | ||
local dao = DAOFactory(conf) | ||
local serf = Serf.new(conf, conf.prefix, dao) | ||
|
||
if args.command == "members" then | ||
local members = assert(serf:members(true)) | ||
for _, v in ipairs(members) do | ||
print(string.format("%s\t%s\t%s", v.name, v.addr, v.status)) | ||
end | ||
elseif args.command == "keygen" then | ||
print(assert(serf:keygen())) | ||
elseif args.command == "reachability" then | ||
print(assert(serf:reachability())) | ||
elseif args.command == "force-leave" then | ||
local node_name = args[1] | ||
assert(node_name ~= nil, "must specify the name of the node to leave") | ||
log("force-leaving %s", node_name) | ||
assert(serf:force_leave(node_name)) | ||
log("left node %s", node_name) | ||
end | ||
end | ||
|
||
local lapp = [[ | ||
Usage: kong cluster COMMAND [OPTIONS] | ||
The available commands are: | ||
members | ||
force-leave <node_name> | ||
keygen | ||
reachability | ||
Options: | ||
-c,--conf (optional string) configuration file | ||
]] | ||
|
||
return { | ||
lapp = lapp, | ||
execute = execute, | ||
sub_commands = { | ||
keygen = true, | ||
members = true, | ||
reachability = true, | ||
["force-leave"] = true | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
local pl_utils = require "pl.utils" | ||
local pl_path = require "pl.path" | ||
local pl_file = require "pl.file" | ||
local kill = require "kong.cmd.utils.kill" | ||
local log = require "kong.cmd.utils.log" | ||
local fmt = string.format | ||
|
||
local _M = {} | ||
|
||
local dnsmasq_bin_name = "dnsmasq" | ||
local dnsmasq_pid_name = "dnsmasq.pid" | ||
local dnsmasq_search_paths = { | ||
"/usr/local/sbin", | ||
"/usr/local/bin", | ||
"/usr/sbin", | ||
"/usr/bin", | ||
"/bin", | ||
"" | ||
} | ||
|
||
function _M.find_bin() | ||
log.verbose("searching for 'dnsmasq' executable...") | ||
|
||
local found | ||
for _, path in ipairs(dnsmasq_search_paths) do | ||
local path_to_check = pl_path.join(path, dnsmasq_bin_name) | ||
local cmd = fmt("%s -v", path_to_check) | ||
if pl_utils.executeex(cmd) then | ||
found = path_to_check | ||
break | ||
end | ||
end | ||
|
||
if not found then | ||
return nil, "could not find 'dnsmasq' executable" | ||
end | ||
|
||
log.verbose("found 'dnsmasq' executable at %s", found) | ||
|
||
return found | ||
end | ||
|
||
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 | ||
|
||
function _M.start(kong_config, nginx_prefix) | ||
-- is dnsmasq already running in this prefix? | ||
local pid_path = pl_path.join(nginx_prefix, "pids", dnsmasq_pid_name) | ||
if is_running(pid_path) then | ||
log.verbose("dnsmasq already running at %s", pid_path) | ||
return true | ||
else | ||
log.verbose("dnsmasq not running, deleting %s", pid_path) | ||
pl_file.delete(pid_path) | ||
end | ||
|
||
local dnsmasq_bin, err = _M.find_bin() | ||
if not dnsmasq_bin then return nil, err end | ||
|
||
local cmd = fmt("%s -p %d --pid-file=%s -N -o --listen-address=127.0.0.1", | ||
dnsmasq_bin, kong_config.dnsmasq_port, pid_path) | ||
|
||
log.debug("starting dnsmasq: %s", cmd) | ||
|
||
local ok, _, _, stderr = pl_utils.executeex(cmd) | ||
if not ok then return nil, stderr end | ||
|
||
return true | ||
end | ||
|
||
function _M.stop(nginx_prefix) | ||
local pid_path = pl_path.join(nginx_prefix, "pids", dnsmasq_pid_name) | ||
if pl_path.exists(pid_path) then | ||
log.verbose("stopping dnsmasq at %s", pid_path) | ||
return kill(pid_path, "-9") | ||
end | ||
return true | ||
end | ||
|
||
return _M |
Oops, something went wrong.