-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95e24c2
commit 150f856
Showing
3 changed files
with
35 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
local IO = require "kong.tools.io" | ||
local utils = require "kong.tools.utils" | ||
local singletons = require "kong.singletons" | ||
|
||
local _M = {} | ||
|
||
function _M.get_node_name(conf) | ||
return utils.get_hostname().."_"..conf.cluster_listen | ||
local IDENTIFIER = "serf.id" | ||
|
||
function _M.get_node_identifier(conf) | ||
local id = singletons.serf_id | ||
if not id then | ||
id = IO.read_file(IO.path:join(conf.nginx_working_dir, IDENTIFIER)) | ||
singletons.serf_id = id | ||
end | ||
return id | ||
end | ||
|
||
function _M.create_node_identifier(conf) | ||
local path = IO.path:join(conf.nginx_working_dir, IDENTIFIER) | ||
if not IO.file_exists(path) then | ||
local id = utils.get_hostname().."_"..conf.cluster_listen.."_"..utils.random_string() | ||
local _, err = IO.write_to_file(path, id) | ||
if err then | ||
return false, err | ||
end | ||
end | ||
return true | ||
end | ||
|
||
return _M |