Changeset

4335:3a2a01432b5c

Add "reload" command to prosodyctl
author Vladimir Protasov <eoranged@ya.ru>
date Thu, 04 Aug 2011 21:26:15 +0400
parents 4334:cd1b73582711
children 4336:abcbcb15205c
files prosodyctl util/prosodyctl.lua
diffstat 2 files changed, 38 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/prosodyctl	Wed Jul 27 14:25:05 2011 -0400
+++ b/prosodyctl	Thu Aug 04 21:26:15 2011 +0400
@@ -538,6 +538,27 @@
 	print("");
 end
 
+function commands.reload(arg)
+	if arg[1] == "--help" then
+		show_usage([[reload]], [[Reload prosody configuration file]]);
+		return 1;
+	end
+
+	if not prosodyctl.isrunning() then
+		show_message("Prosody is not running");
+		return 1;
+	end
+	
+	local ok, ret = prosodyctl.reload();
+	if ok then
+		
+		show_message("Config updated");
+		return 0;
+	end
+
+	show_message(error_messages[ret]);
+	return 1;
+end
 -- ejabberdctl compatibility
 
 function commands.register(arg)
@@ -641,7 +662,7 @@
 	print("Where COMMAND may be one of:\n");
 
 	local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" };
-	local commands_order = { "adduser", "passwd", "deluser", "start", "stop", "restart", "about" };
+	local commands_order = { "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", "about" };
 
 	local done = {};
 
--- a/util/prosodyctl.lua	Wed Jul 27 14:25:05 2011 -0400
+++ b/util/prosodyctl.lua	Thu Aug 04 21:26:15 2011 +0400
@@ -238,3 +238,19 @@
 	signal.kill(pid, signal.SIGTERM);
 	return true;
 end
+
+function reload()
+	local ok, ret = _M.isrunning();
+	if not ok then
+		return ok, ret;
+	end
+	if not ret then
+		return false, "not-running";
+	end
+	
+	local ok, pid = _M.getpid()
+	if not ok then return false, pid; end
+	
+	signal.kill(pid, signal.SIGHUP);
+	return true;
+end