diff options
Diffstat (limited to 'src/daq/nginx-lua/s5-nginx-init.lua')
-rw-r--r-- | src/daq/nginx-lua/s5-nginx-init.lua | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/daq/nginx-lua/s5-nginx-init.lua b/src/daq/nginx-lua/s5-nginx-init.lua index 9d73603..7270e23 100644 --- a/src/daq/nginx-lua/s5-nginx-init.lua +++ b/src/daq/nginx-lua/s5-nginx-init.lua @@ -34,22 +34,37 @@ -- -- http { -- lua_shared_dict sfive 64k; --- lua_shared_dict sfive_log 64m; +-- lua_shared_dict sfive_locks 64k; +-- lua_shared_dict sfive_data 64m; -- init_by_lua_file '/path/to/s5-nginx-init.lua'; -- } -- ngx.log(ngx.DEBUG, "SFive: loaded") + +locks = require "resty.lock" + local sfive = ngx.shared.sfive sfive:flush_all() sfive:flush_expired() -local sfive_log = ngx.shared.sfive_log -sfive_log:flush_all() -sfive_log:flush_expired() +local sfive_data = ngx.shared.sfive_data +sfive_data:flush_all() +sfive_data:flush_expired() -local ok, err, force = sfive:set("log:idx", 0) -if not ok then - ngx.log(ngx.ERR, "SFive(init): creating log index counter failed: " .. err) +-- try to create locks so we get an error on init and not on first usage +local lock = locks:new("sfive_locks") +local elapsed, err = lock:lock("test") +if not elapsed then + ngx.log(ngx.ERR, "SFive(init): lock error: " .. err) else - ngx.log(ngx.INFO, "SFive(init): initialized successfully!") + local ok, err, force = sfive:set("log:idx", 0) + if not ok then + ngx.log(ngx.ERR, "SFive(init): creating log index counter failed: " .. err) + else + ngx.log(ngx.INFO, "SFive(init): initialized successfully!") + end + ok, err = lock:unlock("test") + if not ok then + ngx.log(ngx.ERR, "SFive(init): unlock error: " .. err) + end end |