Skip to content

Commit

Permalink
fix(rc1) migrations + serf event handler script
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Aug 1, 2016
1 parent 4873f74 commit eca0b0c
Showing 3 changed files with 41 additions and 8 deletions.
35 changes: 33 additions & 2 deletions kong/cmd/utils/prefix_handler.lua
Original file line number Diff line number Diff line change
@@ -36,9 +36,37 @@ client:request { \
} \
}"
resty -e "$CMD"
%s -e "$CMD"
]]

local resty_bin_name = "resty"
local resty_search_paths = {
"/usr/local/openresty/bin",
""
}

local function find_resty_bin()
log.verbose("searching for OpenResty 'resty' executable...")

local found
for _, path in ipairs(resty_search_paths) do
local path_to_check = pl_path.join(path, resty_bin_name)
local cmd = fmt("%s -v", path_to_check)
if pl_utils.executeex(cmd) then
found = path_to_check
break
end
end

if not found then
return nil, "could not find OpenResty 'resty' executable"
end

log.verbose("found OpenResty 'resty' executable at %s", found)

return found
end

local function gen_default_ssl_cert(kong_config)
-- create SSL folder
local ok, err = pl_dir.makepath(pl_path.join(kong_config.prefix, "ssl"))
@@ -160,8 +188,11 @@ local function prepare_prefix(kong_config, nginx_custom_template_path)
pl_file.write(kong_config.serf_node_id, id)
end

local resty_bin, err = find_resty_bin()
if not resty_bin then return nil, err end

log.verbose("saving Serf shell script handler in %s", kong_config.serf_event)
local script = fmt(script_template, "127.0.0.1", kong_config.admin_port)
local script = fmt(script_template, "127.0.0.1", kong_config.admin_port, resty_bin)
pl_file.write(kong_config.serf_event, script)
local ok, _, _, stderr = pl_utils.executeex("chmod +x "..kong_config.serf_event)
if not ok then return nil, stderr end
7 changes: 4 additions & 3 deletions kong/plugins/rate-limiting/migrations/cassandra.lua
Original file line number Diff line number Diff line change
@@ -24,6 +24,10 @@ return {
for i = 1, #rows do
local rate_limiting = rows[i]

-- Delete the old one to avoid conflicts when inserting the new one
local _, err = dao.plugins:delete(rate_limiting)
if err then return err end

local _, err = dao.plugins:insert {
name = "rate-limiting",
api_id = rate_limiting.api_id,
@@ -42,9 +46,6 @@ return {
}
}
if err then return err end

_, err = dao.plugins:delete(rate_limiting)
if err then return err end
end
end
}
7 changes: 4 additions & 3 deletions kong/plugins/rate-limiting/migrations/postgres.lua
Original file line number Diff line number Diff line change
@@ -42,6 +42,10 @@ return {
for i = 1, #rows do
local rate_limiting = rows[i]

-- Delete the old one to avoid conflicts when inserting the new one
local _, err = dao.plugins:delete(rate_limiting)
if err then return err end

local _, err = dao.plugins:insert {
name = "rate-limiting",
api_id = rate_limiting.api_id,
@@ -60,9 +64,6 @@ return {
}
}
if err then return err end

_, err = dao.plugins:delete(rate_limiting)
if err then return err end
end
end
}

0 comments on commit eca0b0c

Please sign in to comment.