-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathinit.conf
108 lines (82 loc) · 3.24 KB
/
init.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
init_by_lua_block {
-- require("jit.v").start("dump.txt")
-- require('jit.p').start('vl')
-- require('jit.dump').start('bsx', 'jit.log')
local log = require('resty.log.log')
log:patch_ngx_log_on_debug()
if os.getenv('CI') == 'true' then
pcall(require, 'luacov.runner')
end
local luacov = package.loaded['luacov.runner']
if luacov then
local pwd = os.getenv('PWD') .. package.config:sub(1, 1)
local pid = require("ngx.process").get_master_pid
if not pid then
do
local ffi = require("ffi")
ffi.cdef[[int getpid(void);]]
pid = ffi.C.getpid()
end
end
local config = { }
for _, option in ipairs({"statsfile", "reportfile"}) do
-- properly expand current working dir, workaround for https://github.com/openresty/resty-cli/issues/35
config[option] = pwd .. luacov.defaults[option]
luacov.defaults[option] = pwd
end
luacov.defaults.savestepsize = 3
jit.off()
luacov.init()
for option, value in pairs(config) do
luacov.configuration[option] = value
end
end
require("resty.core")
local resty_env = require('resty.env')
-- WARNING, WARNING, WARNING: this is insane hack and should not be touched
-- This file is not templated by Liquid, because it is used by not blackbox integration tests (Search for TEST_NGINX_HTTP_CONFIG).
-- So it cannot be templated by liquid, to lift env variables and persist them in the configuration.
-- This is a workaround so we can store environment at the time of building the config into the config itself.
-- {% raw %} {{ ENV }} {% endraw %} is both valid Liquid template and Lua code.
-- In Lua it is a table with another empty table inside. In Liquid it prints variable ENV.
-- This ENV variable is defined in the main nginx.conf.liquid and injected when including this partial.
-- The content of the ENV variable is a Lua table, so when rendered it actually can run ipairs on it.
for k,v in pairs({{ ENV }}) do
if type(k) == 'string' and not resty_env.value(k) then
resty_env.set(k,v)
end
end
require('resty.resolver').init()
require('apicast.loader')
local env = require('apicast.cli.environment').load()
local context = env:context()
for k,v in pairs(context.env or {}) do
resty_env.set(k,v)
end
local module = require('apicast.executor')
if not module then
ngx.log(ngx.EMERG, 'fatal error when loading the root module')
os.exit(1)
end
if context.policy_chain then
module = module.new(context.policy_chain)
package.loaded['apicast.executor'] = module
end
module:init()
collectgarbage("collect")
}
init_worker_by_lua_block {
local luacov = package.loaded['luacov.runner']
if luacov then
luacov.configuration.statsfile = luacov.defaults.statsfile .. 'luacov.stats.' .. ngx.worker.pid() .. '.out'
luacov.resume()
ngx.timer.every(100, function(premature)
if premature then
luacov.save_stats()
luacov.tick = true
end
end)
end
require('apicast.executor'):init_worker()
}
lua_shared_dict init 16k;