Skip to content

Commit

Permalink
Merge pull request #1645 from Mashape/fix/start-stopping-alread-running
Browse files Browse the repository at this point in the history
fix(cli) prevent start from stopping already-running Kong
  • Loading branch information
thibaultcha authored Sep 15, 2016
2 parents b0fce3e + 3673504 commit f676803
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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)

0 comments on commit f676803

Please sign in to comment.