Comparison

util/prosodyctl.lua @ 13491:cf367ab36fcc

util.prosodyctl: Use notify socket to wait for Prosody to be ready Previously, prosodyctl only waits for the pidfile to appear, which does not necessarily mean that Prosody is fully ready to receive traffic. By waiting until Prosody says it's ready via the systemd notify socket we know for sure that Prosody is really ready. Notably this should ensure that when running `make integration-test` Prosody is really ready when Scansion starts running tests. Not sure if this timeout handling is optimal.
author Kim Alvefur <zash@zash.se>
date Sun, 19 May 2024 13:06:55 +0200
parent 12975:d10957394a3c
child 13647:2b3d49936518
comparison
equal deleted inserted replaced
13490:6f840763fc73 13491:cf367ab36fcc
13 local storagemanager = require "prosody.core.storagemanager"; 13 local storagemanager = require "prosody.core.storagemanager";
14 local usermanager = require "prosody.core.usermanager"; 14 local usermanager = require "prosody.core.usermanager";
15 local interpolation = require "prosody.util.interpolation"; 15 local interpolation = require "prosody.util.interpolation";
16 local signal = require "prosody.util.signal"; 16 local signal = require "prosody.util.signal";
17 local set = require "prosody.util.set"; 17 local set = require "prosody.util.set";
18 local path = require"prosody.util.paths";
18 local lfs = require "lfs"; 19 local lfs = require "lfs";
19 local type = type; 20 local type = type;
21
22 local have_socket_unix, socket_unix = pcall(require, "socket.unix");
23 have_socket_unix = have_socket_unix and type(socket_unix) == "table"; -- was a function in older LuaSocket
20 24
21 local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep; 25 local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep;
22 26
23 local io, os = io, os; 27 local io, os = io, os;
24 local print = print; 28 local print = print;
175 return ok, ret; 179 return ok, ret;
176 end 180 end
177 if ret then 181 if ret then
178 return false, "already-running"; 182 return false, "already-running";
179 end 183 end
184 local notify_socket;
185 if have_socket_unix then
186 local notify_path = path.join(prosody.paths.data, "notify.sock");
187 os.remove(notify_path);
188 lua = string.format("NOTIFY_SOCKET=%q %s", notify_path, lua);
189 notify_socket = socket_unix.dgram();
190 local ok = notify_socket:setsockname(notify_path);
191 if not ok then return false, "notify-failed"; end
192 end
180 if not source_dir then 193 if not source_dir then
181 os.execute(lua .. "./prosody -D"); 194 os.execute(lua .. "./prosody -D");
182 else 195 else
183 os.execute(lua .. source_dir.."/../../bin/prosody -D"); 196 os.execute(lua .. source_dir.."/../../bin/prosody -D");
184 end 197 end
198
199 if notify_socket then
200 for i = 1, 5 do
201 notify_socket:settimeout(i);
202 if notify_socket:receivefrom() == "READY=1" then
203 return true;
204 end
205 end
206 return false, "not-ready";
207 end
208
185 return true; 209 return true;
186 end 210 end
187 211
188 local function stop() 212 local function stop()
189 local ok, ret = isrunning(); 213 local ok, ret = isrunning();