Skip to content

Commit

Permalink
Addresses issue #256
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Jul 22, 2015
1 parent 8938a1f commit 5d9f2dc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
1 change: 1 addition & 0 deletions kong-0.4.0-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ build = {
["kong.constants"] = "kong/constants.lua",

["kong.cli.utils"] = "kong/cli/utils/utils.lua",
["kong.cli.utils.dnsmasq"] = "kong/cli/utils/dnsmasq.lua",
["kong.cli.utils.signal"] = "kong/cli/utils/signal.lua",
["kong.cli.utils.input"] = "kong/cli/utils/input.lua",
["kong.cli.db"] = "kong/cli/db.lua",
Expand Down
33 changes: 33 additions & 0 deletions kong/cli/utils/dnsmasq.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local IO = require "kong.tools.io"
local cutils = require "kong.cli.utils"
local constants = require "kong.constants"
local stringy = require "stringy"

local _M = {}

function _M.stop(kong_config)
local pid_file = kong_config.nginx_working_dir.."/"..constants.CLI.DNSMASQ_PID
local _, code = IO.kill_process_by_pid_file(pid_file)
if code and code == 0 then
cutils.logger:info("dnsmasq stopped")
end
end

function _M.start(kong_config)
local cmd = IO.cmd_exists("dnsmasq") and "dnsmasq" or
(IO.cmd_exists("/usr/local/sbin/dnsmasq") and "/usr/local/sbin/dnsmasq" or nil) -- On OS X dnsmasq is at /usr/local/sbin/
if not cmd then
cutils.logger:error_exit("Can't find dnsmasq")
end

-- Start the dnsmasq daemon
local file_pid = kong_config.nginx_working_dir..(stringy.endswith(kong_config.nginx_working_dir, "/") and "" or "/")..constants.CLI.DNSMASQ_PID
local res, code = IO.os_execute(cmd.." -p "..kong_config.dnsmasq_port.." --pid-file="..file_pid.." -N -o")
if code ~= 0 then
cutils.logger:error_exit(res)
else
cutils.logger:info("dnsmasq started")
end
end

return _M
35 changes: 5 additions & 30 deletions kong/cli/utils/signal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ local IO = require "kong.tools.io"
local cutils = require "kong.cli.utils"
local constants = require "kong.constants"
local syslog = require "kong.tools.syslog"
local stringy = require "stringy"
local socket = require "socket"
local dnsmasq = require "kong.cli.utils.dnsmasq"

-- Cache config path, parsed config and DAO factory
local kong_config_path
Expand Down Expand Up @@ -178,31 +178,6 @@ local function prepare_database(args_config)
end)
end

local function stop_dnsmasq(kong_config)
local pid_file = kong_config.nginx_working_dir.."/"..constants.CLI.DNSMASQ_PID
local _, code = IO.kill_process_by_pid_file(pid_file)
if code and code == 0 then
cutils.logger:info("dnsmasq stopped")
end
end

local function start_dnsmasq(kong_config)
local cmd = IO.cmd_exists("dnsmasq") and "dnsmasq" or
(IO.cmd_exists("/usr/local/sbin/dnsmasq") and "/usr/local/sbin/dnsmasq" or nil) -- On OS X dnsmasq is at /usr/local/sbin/
if not cmd then
cutils.logger:error_exit("Can't find dnsmasq")
end

-- Start the dnsmasq
local file_pid = kong_config.nginx_working_dir..(stringy.endswith(kong_config.nginx_working_dir, "/") and "" or "/")..constants.CLI.DNSMASQ_PID
local res, code = IO.os_execute(cmd.." -p "..kong_config.dnsmasq_port.." --pid-file="..file_pid)
if code ~= 0 then
cutils.logger:error_exit(res)
else
cutils.logger:info("dnsmasq started")
end
end

--
-- PUBLIC
--
Expand Down Expand Up @@ -288,11 +263,11 @@ function _M.send_signal(args_config, signal)

-- dnsmasq start/stop
if signal == START then
stop_dnsmasq(kong_config)
dnsmasq.stop(kong_config)
check_port(kong_config.dnsmasq_port)
start_dnsmasq(kong_config)
dnsmasq.start(kong_config)
elseif signal == STOP or signal == QUIT then
stop_dnsmasq(kong_config)
dnsmasq.stop(kong_config)
end

-- Check ulimit value
Expand All @@ -312,7 +287,7 @@ function _M.send_signal(args_config, signal)
local success = os.execute(cmd) == 0

if signal == START and not success then
stop_dnsmasq(kong_config) -- If the start failed, then stop dnsmasq
dnsmasq.stop(kong_config) -- If the start failed, then stop dnsmasq
end

if signal == STOP and success then
Expand Down
4 changes: 2 additions & 2 deletions kong/tools/faker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function Faker:fake_entity(type)
}
elseif type == "plugin_configuration" then
return {
name = "keyauth",
value = { key_names = {"apikey"} }
name = "ratelimiting",
value = { second = 10 }
}
else
error("Entity of type "..type.." cannot be generated.")
Expand Down

0 comments on commit 5d9f2dc

Please sign in to comment.