Skip to content

Commit

Permalink
fix(cmd) check if Kong is running before preparing the prefix
Browse files Browse the repository at this point in the history
If Kong is already running, `kong start` should not "prepare" or
otherwise alter the prefix directory.
  • Loading branch information
flrgh committed Aug 24, 2022
1 parent 50a4b4d commit 5da2a09
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
3 changes: 1 addition & 2 deletions kong/cmd/start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ local function execute(args)
conf.cassandra_timeout = args.db_timeout -- connect + send + read
conf.cassandra_schema_consensus_timeout = args.db_timeout

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

assert(not kill.is_running(conf.nginx_pid),
"Kong is already running in " .. conf.prefix)

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

cleanup_dangling_unix_sockets(conf.prefix)

Expand Down
36 changes: 35 additions & 1 deletion spec/02-integration/02-cmd/02-start_stop_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ describe("kong start/stop #" .. strategy, function()
assert.False(ok)
assert.matches("Kong is already running in " .. helpers.test_conf.prefix, stderr, nil, true)
end)
it("should not stop Kong if already running in prefix", function()
it("should not start Kong if already running in prefix", function()
local kill = require "kong.cmd.utils.kill"

assert(helpers.kong_exec("start --prefix " .. helpers.test_conf.prefix, {
Expand All @@ -517,6 +517,40 @@ describe("kong start/stop #" .. strategy, function()

assert(kill.is_running(helpers.test_conf.nginx_pid))
end)

it("does not prepare the prefix directory if Kong is already running", function()
local prefix = helpers.test_conf.prefix

assert(helpers.kong_exec("start --prefix " .. prefix, {
database = "off",
nginx_main_worker_processes = "1",
}))

finally(function()
helpers.stop_kong()
end)

local kong_env = prefix .. "/.kong_env"

local before, err = helpers.file.read(kong_env)
assert.truthy(before, "failed reading .kong_env: " .. tostring(err))
assert.matches("nginx_main_worker_processes = 1", before) -- sanity

local ok, stderr = helpers.kong_exec("start --prefix " .. prefix, {
database = "off",
nginx_main_worker_processes = "2",
})

assert.falsy(ok)
assert.matches("Kong is already running", stderr)

local after
after, err = helpers.file.read(kong_env)
assert.truthy(after, "failed reading .kong_env: " .. tostring(err))

assert.equal(before, after, ".kong_env file was rewritten")
end)

it("ensures the required shared dictionaries are defined", function()
local constants = require "kong.constants"
local pl_file = require "pl.file"
Expand Down

0 comments on commit 5da2a09

Please sign in to comment.