Skip to content

Commit

Permalink
Merge pull request Kong#975 from Mashape/fix/serf-log
Browse files Browse the repository at this point in the history
Serf log is stored in the nginx_working_dir
  • Loading branch information
subnetmarco committed Feb 10, 2016
2 parents d113179 + 26857a1 commit 8446799
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions kong/cli/services/serf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ local dao = require "kong.tools.dao_loader"
local Serf = BaseService:extend()

local SERVICE_NAME = "serf"
local LOG_FILE = "/tmp/"..SERVICE_NAME..".log"
local START_TIMEOUT = 10
local EVENT_NAME = "kong"

function Serf:new(configuration)
local nginx_working_dir = configuration.nginx_working_dir

self._configuration = configuration
self._script_path = nginx_working_dir
local path_prefix = nginx_working_dir
..(stringy.endswith(nginx_working_dir, "/") and "" or "/")
.."serf_event.sh"
self._script_path = path_prefix.."serf_event.sh"
self._log_path = path_prefix.."serf.log"
self._dao_factory = dao.load(self._configuration)
Serf.super.new(self, SERVICE_NAME, nginx_working_dir)
end
Expand Down Expand Up @@ -155,12 +155,12 @@ function Serf:start()

setmetatable(cmd_args, require "kong.tools.printable")
local str_cmd_args = tostring(cmd_args)
local res, code = IO.os_execute("nohup "..cmd.." agent "..str_cmd_args.." > "..LOG_FILE.." 2>&1 & echo $! > "..self._pid_file_path)
local res, code = IO.os_execute("nohup "..cmd.." agent "..str_cmd_args.." > "..self._log_path.." 2>&1 & echo $! > "..self._pid_file_path)
if code == 0 then

-- Wait for process to start, with a timeout
local start = os.time()
while not (IO.file_exists(LOG_FILE) and string.match(IO.read_file(LOG_FILE), "running") or (os.time() > start + START_TIMEOUT)) do
while not (IO.file_exists(self._log_path) and string.match(IO.read_file(self._log_path), "running") or (os.time() > start + START_TIMEOUT)) do
-- Wait
end

Expand All @@ -171,7 +171,7 @@ function Serf:start()
return self:_autojoin(node_name)
else
-- Get last error message
local parts = stringy.split(IO.read_file(LOG_FILE), "\n")
local parts = stringy.split(IO.read_file(self._log_path), "\n")
return nil, "Could not start serf: "..string.gsub(parts[#parts - 1], "==> ", "")
end
else
Expand Down

0 comments on commit 8446799

Please sign in to comment.