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

feat: test if pid file process is running. #115 #131

Merged
merged 1 commit into from
Apr 10, 2015
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
18 changes: 15 additions & 3 deletions src/cli/utils/signal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,22 @@ function _M.is_running(args_config)
-- Get configuration from default or given path
local _, kong_config = get_kong_config_path(args_config)

local pid = IO.path:join(kong_config.nginx_working_dir, constants.CLI.NGINX_PID)
local pid_file = IO.path:join(kong_config.nginx_working_dir, constants.CLI.NGINX_PID)

if not IO.file_exists(pid) then
return false, "Not running. Could not find pid at: "..pid
if IO.file_exists(pid_file) then
local pid = IO.read_file(pid_file)
if os.execute("kill -0 "..pid) == 0 then
return true
else
cutils.logger:log("Removing pid at: "..pid_file)
local _, err = os.remove(pid_file)
if err then
error(err)
end
return false, "Not running. Could not find pid: "..pid
end
else
return false, "Not running. Could not find pid at: "..pid_file
end

return true
Expand Down
6 changes: 5 additions & 1 deletion src/cli/utils/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ for _, v in ipairs({"red", "green", "yellow"}) do
colors[v] = function(str) return ansicolors("%{"..v.."}"..str.."%{reset}") end
end

function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end

--
-- Logging
--
Expand All @@ -29,7 +33,7 @@ end

function Logger:log(str)
if not self.silent then
print(str)
print(trim(str))
end
end

Expand Down