diff --git a/CHANGELOG.md b/CHANGELOG.md index 706381d5793..5cb502a81af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ - Serf commands executed by a running Kong node are now logged in the Nginx error logs with a `DEBUG` level. [#2410](https://github.com/Mashape/kong/pull/2410) +- Checking that core Lua shared dictionaries are declared in the configuration. + [#2466](https://github.com/Mashape/kong/pull/2466) - Plugins: - :fireworks: **New Request termination plugin**. This plugin allows to temporarily disable an API and return a pre-configured response status and diff --git a/kong/constants.lua b/kong/constants.lua index a66cc7d4253..4cdcf76c4f2 100644 --- a/kong/constants.lua +++ b/kong/constants.lua @@ -69,5 +69,6 @@ return { }, CACHE = { CLUSTER = "cluster" - } + }, + DICTS = { "kong", "cache", "cache_locks", "process_events", "cassandra"} } diff --git a/kong/kong.lua b/kong/kong.lua index fd59612dcdc..1a614a20fa4 100644 --- a/kong/kong.lua +++ b/kong/kong.lua @@ -121,6 +121,15 @@ end local Kong = {} function Kong.init() + -- Check shared dictionaries + for _, dict in ipairs(constants.DICTS) do + if not ngx.shared[dict] then + error("missing shared dict in Nginx configuration, are you ".. + "using a custom template? Make sure the 'lua_shared_dict ".. + dict.." [SIZE];' directive is defined.") + end + end + local pl_path = require "pl.path" local conf_loader = require "kong.conf_loader" diff --git a/spec/02-integration/01-cmd/02-start_stop_spec.lua b/spec/02-integration/01-cmd/02-start_stop_spec.lua index 4babf82f108..f85dfa6ecb6 100644 --- a/spec/02-integration/01-cmd/02-start_stop_spec.lua +++ b/spec/02-integration/01-cmd/02-start_stop_spec.lua @@ -199,5 +199,28 @@ describe("kong start/stop", function() assert(kill.is_running(helpers.test_conf.nginx_pid)) end) + it("checks that the shared dictionaries exist", function() + local constants = require "kong.constants" + local pl_file = require "pl.file" + + local templ_fixture = "spec/fixtures/custom_nginx.template" + local new_templ_fixture = "spec/fixtures/custom_nginx.template.tmp" + + for _, dict in ipairs(constants.DICTS) do + -- Remove shared dictionary entry + assert(os.execute( + "sed '/lua_shared_dict "..dict.." .*;/d' "..templ_fixture.." > " + ..new_templ_fixture)) + + local _, stderr = helpers.kong_exec("start --nginx-conf " + ..new_templ_fixture) + assert.matches( + "missing shared dict in Nginx configuration, ".. + "are you using a custom template? Make sure the 'lua_shared_dict " + ..dict.." [SIZE];' directive is defined.", stderr, nil, true) + end + + pl_file.delete(new_templ_fixture) + end) end) end)