summaryrefslogtreecommitdiff
path: root/src/daq/nginx-lua/s5-nginx-init.lua
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2014-10-18 00:32:21 +0200
committerChristian Pointner <equinox@spreadspace.org>2014-10-18 00:32:21 +0200
commitf3c1a77d7a4814f3dd3be5dae6d530471a8d58a5 (patch)
treed3551ea4333ab65820a6e96685649cfb76283d99 /src/daq/nginx-lua/s5-nginx-init.lua
parentadded proposal for protocol upgrade (diff)
moved to resty-lock for fetchold-lua-ngx
Diffstat (limited to 'src/daq/nginx-lua/s5-nginx-init.lua')
-rw-r--r--src/daq/nginx-lua/s5-nginx-init.lua31
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