Skip to content

Commit

Permalink
fix(cmd) check db connection on reload
Browse files Browse the repository at this point in the history
### Summary

Database connection may be changed on `kong reload`, so it is good that we
check that before we signal to actual Kong server process to `reload`.
  • Loading branch information
bungle committed May 4, 2022
1 parent bc2879d commit 0b000d2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kong/cmd/reload.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
local prefix_handler = require "kong.cmd.utils.prefix_handler"
local nginx_signals = require "kong.cmd.utils.nginx_signals"
local conf_loader = require "kong.conf_loader"
local kong_global = require "kong.global"
local pl_path = require "pl.path"
local pl_file = require "pl.file"
local log = require "kong.cmd.utils.log"
local DB = require "kong.db"


local function execute(args)
log.disable()
Expand Down Expand Up @@ -34,11 +37,19 @@ local function execute(args)
end

assert(prefix_handler.prepare_prefix(conf, args.nginx_conf, nil, true))

_G.kong = kong_global.new()
kong_global.init_pdk(_G.kong, conf)

local db = assert(DB.new(conf))
assert(db:init_connector())

assert(nginx_signals.reload(conf))

log("Kong reloaded")
end


local lapp = [[
Usage: kong reload [OPTIONS]
Expand All @@ -56,6 +67,7 @@ Options:
--nginx-conf (optional string) custom Nginx configuration template
]]


return {
lapp = lapp,
execute = execute
Expand Down
16 changes: 16 additions & 0 deletions spec/02-integration/02-cmd/03-reload_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,22 @@ describe("kong reload #" .. strategy, function()
assert.False(ok)
assert.matches("Error: nginx not running in prefix: " .. helpers.test_conf.prefix, err, nil, true)
end)

if strategy ~= "off" then
it("complains when database connection is invalid", function()
assert(helpers.start_kong({
proxy_listen = "0.0.0.0:9002"
}, nil, true))

local ok = helpers.kong_exec("reload --conf " .. helpers.test_conf_path, {
database = strategy,
pg_port = 1234,
cassandra_port = 1234,
})

assert.False(ok)
end)
end
end)
end)

Expand Down

0 comments on commit 0b000d2

Please sign in to comment.