Skip to content

Commit

Permalink
Merge pull request Kong#1640 from Mashape/hotfix/kill-against-non-exi…
Browse files Browse the repository at this point in the history
…stent-pid

hotfix(cli) prevent executing 'kill' on missing pids
  • Loading branch information
thibaultcha authored Sep 16, 2016
2 parents 4ff3068 + 3a10d1b commit 9920679
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions kong/cmd/utils/kill.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
local pl_path = require "pl.path"
local log = require "kong.cmd.utils.log"

local cmd_tmpl = [[
kill %s `cat %s` >/dev/null 2>&1
]]
local cmd_tmpl = [[kill %s `cat %s` >/dev/null 2>&1]]

local function kill(pid_file, args)
log.debug("sending signal to pid at: %s", pid_file)
local cmd = string.format(cmd_tmpl, args or "-0", pid_file)
return os.execute(cmd)
if pl_path.exists(pid_file) then
log.debug(cmd)
return os.execute(cmd)
else
log.debug("no pid file at: %s", pid_file)
return 0
end
end

local function is_running(pid_file)
-- we do our own pid_file exists check here because
-- we want to return `nil` in case of NOT running,
-- and not `0` like `kill` would return.
if pl_path.exists(pid_file) then
return kill(pid_file) == 0
end
Expand Down

0 comments on commit 9920679

Please sign in to comment.