Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli) prevent start from stopping already-running Kong #1645

Merged
merged 1 commit into from
Sep 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions kong/cmd/start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ 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 kill = require "kong.cmd.utils.kill"
local log = require "kong.cmd.utils.log"

local function execute(args)
local conf = assert(conf_loader(args.conf, {
prefix = args.prefix
}))

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

local dao = DAOFactory(conf)
local err
xpcall(function()
Expand Down
19 changes: 17 additions & 2 deletions spec/02-integration/01-cmd/02-start_stop_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe("kong start/stop", function()
assert.False(ok)
assert.matches("Error: no such prefix: .*/inexistent", stderr)
end)
it("notifies when Nginx is already running", function()
it("notifies when Kong is already running", function()
assert(helpers.kong_exec("start --prefix "..helpers.test_conf.prefix, {
pg_database = helpers.test_conf.pg_database
}))
Expand All @@ -201,7 +201,7 @@ describe("kong start/stop", function()
pg_database = helpers.test_conf.pg_database
})
assert.False(ok)
assert.matches("nginx is already running in "..helpers.test_conf.prefix, stderr, nil, true)
assert.matches("Kong is already running in "..helpers.test_conf.prefix, stderr, nil, true)
end)
it("stops other services when could not start", function()
local kill = require "kong.cmd.utils.kill"
Expand All @@ -225,5 +225,20 @@ describe("kong start/stop", function()
assert.falsy(kill.is_running(helpers.test_conf.dnsmasq_pid))
assert.falsy(kill.is_running(helpers.test_conf.serf_pid))
end)
it("should not stop Kong if already running in prefix", function()
local kill = require "kong.cmd.utils.kill"

assert(helpers.kong_exec("start --prefix "..helpers.test_conf.prefix, {
pg_database = helpers.test_conf.pg_database
}))

local ok, stderr = helpers.kong_exec("start --prefix "..helpers.test_conf.prefix, {
pg_database = helpers.test_conf.pg_database
})
assert.False(ok)
assert.matches("Kong is already running in "..helpers.test_conf.prefix, stderr, nil, true)

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