diff options
author | Kim Alvefur <zash@zash.se> | 2024-05-19 13:06:55 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2024-05-19 13:06:55 +0200 |
commit | 4701e73a72477d156494257acc4bf9897d6d762a (patch) | |
tree | 5f8e839f401f59ffe414ae3bc39ca18151cdf929 /util/prosodyctl.lua | |
parent | 2647c561060c75bac537ff4a77543cf7078dc713 (diff) | |
download | prosody-4701e73a72477d156494257acc4bf9897d6d762a.tar.gz prosody-4701e73a72477d156494257acc4bf9897d6d762a.zip |
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.
Diffstat (limited to 'util/prosodyctl.lua')
-rw-r--r-- | util/prosodyctl.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index d256e558..9cb4b4dd 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -15,9 +15,13 @@ local usermanager = require "prosody.core.usermanager"; local interpolation = require "prosody.util.interpolation"; local signal = require "prosody.util.signal"; local set = require "prosody.util.set"; +local path = require"prosody.util.paths"; local lfs = require "lfs"; local type = type; +local have_socket_unix, socket_unix = pcall(require, "socket.unix"); +have_socket_unix = have_socket_unix and type(socket_unix) == "table"; -- was a function in older LuaSocket + local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep; local io, os = io, os; @@ -177,11 +181,31 @@ local function start(source_dir, lua) if ret then return false, "already-running"; end + local notify_socket; + if have_socket_unix then + local notify_path = path.join(prosody.paths.data, "notify.sock"); + os.remove(notify_path); + lua = string.format("NOTIFY_SOCKET=%q %s", notify_path, lua); + notify_socket = socket_unix.dgram(); + local ok = notify_socket:setsockname(notify_path); + if not ok then return false, "notify-failed"; end + end if not source_dir then os.execute(lua .. "./prosody -D"); else os.execute(lua .. source_dir.."/../../bin/prosody -D"); end + + if notify_socket then + for i = 1, 5 do + notify_socket:settimeout(i); + if notify_socket:receivefrom() == "READY=1" then + return true; + end + end + return false, "not-ready"; + end + return true; end |