aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/prosodyctl.lua7
-rw-r--r--util/prosodyctl/shell.lua8
-rw-r--r--util/startup.lua8
3 files changed, 19 insertions, 4 deletions
diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua
index 9cb4b4dd..c6856526 100644
--- a/util/prosodyctl.lua
+++ b/util/prosodyctl.lua
@@ -40,6 +40,7 @@ local error_messages = setmetatable({
["unable-to-save-data"] = "Unable to store, perhaps you don't have permission?";
["no-pidfile"] = "There is no 'pidfile' option in the configuration file, see https://prosody.im/doc/prosodyctl#pidfile for help";
["invalid-pidfile"] = "The 'pidfile' option in the configuration file is not a string, see https://prosody.im/doc/prosodyctl#pidfile for help";
+ ["pidfile-not-locked"] = "Stale pidfile found. Prosody is probably not running.";
["no-posix"] = "The mod_posix module is not enabled in the Prosody config file, see https://prosody.im/doc/prosodyctl for more info";
["no-such-method"] = "This module has no commands";
["not-running"] = "Prosody is not running";
@@ -143,8 +144,14 @@ local function getpid()
return false, "pidfile-read-failed", err;
end
+ -- Check for a lock on the file
local locked, err = lfs.lock(file, "w"); -- luacheck: ignore 211/err
if locked then
+ -- Prosody keeps the pidfile locked while it is running.
+ -- We successfully locked the file, which means Prosody is not
+ -- running and the pidfile is stale (somehow it was not
+ -- cleaned up). We'll abort here, to avoid sending signals to
+ -- a non-Prosody PID.
file:close();
return false, "pidfile-not-locked";
end
diff --git a/util/prosodyctl/shell.lua b/util/prosodyctl/shell.lua
index d6d885d8..a0fbb09c 100644
--- a/util/prosodyctl/shell.lua
+++ b/util/prosodyctl/shell.lua
@@ -64,6 +64,13 @@ local function printbanner()
print("https://prosody.im/doc/console\n");
end
+local function check()
+ local lfs = require "lfs";
+ local socket_path = path.resolve_relative_path(prosody.paths.data, config.get("*", "admin_socket") or "prosody.sock");
+ local state = lfs.attributes(socket_path, "mode");
+ return state == "socket";
+end
+
local function start(arg) --luacheck: ignore 212/arg
local client = adminstream.client();
local opts, err, where = parse_args(arg);
@@ -180,4 +187,5 @@ end
return {
shell = start;
+ available = check;
};
diff --git a/util/startup.lua b/util/startup.lua
index c54fa56d..2fa2d0b2 100644
--- a/util/startup.lua
+++ b/util/startup.lua
@@ -814,12 +814,12 @@ function startup.hook_posix_signals()
end);
end
-function startup.systemd_notify()
+function startup.notification_socket()
local notify_socket_name = os.getenv("NOTIFY_SOCKET");
if not notify_socket_name then return end
local have_unix, unix = pcall(require, "socket.unix");
if not have_unix or type(unix) ~= "table" then
- log("error", "LuaSocket without UNIX socket support, can't notify systemd.")
+ log("error", "LuaSocket without UNIX socket support, can't notify process manager.")
return os.exit(1);
end
log("debug", "Will notify on socket %q", notify_socket_name);
@@ -827,7 +827,7 @@ function startup.systemd_notify()
local notify_socket = unix.dgram();
local ok, err = notify_socket:setpeername(notify_socket_name);
if not ok then
- log("error", "Could not connect to systemd notification socket %q: %q", notify_socket_name, err);
+ log("error", "Could not connect to notification socket %q: %q", notify_socket_name, err);
return os.exit(1);
end
local time = require "prosody.util.time";
@@ -928,7 +928,7 @@ function startup.prosody()
startup.posix_daemonize();
startup.write_pidfile();
startup.hook_posix_signals();
- startup.systemd_notify();
+ startup.notification_socket();
startup.prepare_to_start();
startup.notify_started();
end