Skip to content

Commit

Permalink
hotfix(cli) prevent executing 'kill' on missing pids
Browse files Browse the repository at this point in the history
This would occasionally output some ungraceful "no pid file at" error to
`stderr`. Instead, we catch those and now print a proper debug log.
  • Loading branch information
thibaultcha committed Sep 14, 2016
1 parent 4ff3068 commit 3a10d1b
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 3a10d1b

Please sign in to comment.