Add "reload" command to prosodyctl
authorVladimir Protasov <eoranged@ya.ru>
Thu, 4 Aug 2011 17:26:15 +0000 (21:26 +0400)
committerVladimir Protasov <eoranged@ya.ru>
Thu, 4 Aug 2011 17:26:15 +0000 (21:26 +0400)
prosodyctl
util/prosodyctl.lua

index bb90b685e3e7a27e360b4128adf5aea387aaeeb1..470a7d5533c855cbe47b2fce534178abfed8ec0e 100755 (executable)
@@ -538,6 +538,27 @@ function commands.about(arg)
        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 @@ if not commands[command] then -- Show help for all commands
        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 = {};
 
index aa1850b259e14e07d0abb277a44956e4c62f6092..d0045abc9d251ce3eaebf0e1666f65002dfb3ea7 100644 (file)
@@ -238,3 +238,19 @@ function stop()
        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