prosody, mod_c2s, mod_s2s: Move closing of c2s and s2s sessions to respective plugins
authorKim Alvefur <zash@zash.se>
Fri, 28 Dec 2012 13:33:47 +0000 (14:33 +0100)
committerKim Alvefur <zash@zash.se>
Fri, 28 Dec 2012 13:33:47 +0000 (14:33 +0100)
plugins/mod_c2s.lua
plugins/mod_s2s/mod_s2s.lua
prosody

index 720851137da87eda1a58417d40a4f7a07f3fc21a..89d678caedc62ef446ab0163f353a7cd5345c42e 100644 (file)
@@ -265,6 +265,15 @@ function listener.associate_session(conn, session)
        sessions[conn] = session;
 end
 
+module:hook("server-stopping", function(event)
+       local reason = event.reason;
+       for _, session in pairs(sessions) do
+               session:close{ condition = "system-shutdown", text = reason };
+       end
+end, 1000);
+
+
+
 module:provides("net", {
        name = "c2s";
        listener = listener;
index 788a64af606e3f20837d496a3635e1b1ee5aa303..ad628a9b17a3fe711f819bdd3fe5b38af3514b75 100644 (file)
@@ -506,6 +506,15 @@ end
 
 s2sout.set_listener(listener);
 
+module:hook("server-stopping", function(event)
+       local reason = event.reason;
+       for _, session in pairs(sessions) do
+               session:close{ condition = "system-shutdown", text = reason };
+       end
+end,500);
+
+
+
 module:provides("net", {
        name = "s2s";
        listener = listener;
diff --git a/prosody b/prosody
index c1606874a4a6f77da359e1dce9f6e88458161119..da77719daf317b8a99ca08f1a89af71b40299a5e 100755 (executable)
--- a/prosody
+++ b/prosody
@@ -374,43 +374,6 @@ end
 function cleanup()
        log("info", "Shutdown status: Cleaning up");
        prosody.events.fire_event("server-cleanup");
-       
-       -- Ok, we're quitting I know, but we
-       -- need to do some tidying before we go :)
-       server.setquitting(false);
-       
-       log("info", "Shutdown status: Closing all active sessions");
-       for hostname, host in pairs(hosts) do
-               log("debug", "Shutdown status: Closing client connections for %s", hostname)
-               if host.sessions then
-                       local reason = { condition = "system-shutdown", text = "Server is shutting down" };
-                       if prosody.shutdown_reason then
-                               reason.text = reason.text..": "..prosody.shutdown_reason;
-                       end
-                       for username, user in pairs(host.sessions) do
-                               for resource, session in pairs(user.sessions) do
-                                       log("debug", "Closing connection for %s@%s/%s", username, hostname, resource);
-                                       session:close(reason);
-                               end
-                       end
-               end
-       
-               log("debug", "Shutdown status: Closing outgoing s2s connections from %s", hostname);
-               if host.s2sout then
-                       for remotehost, session in pairs(host.s2sout) do
-                               if session.close then
-                                       session:close("system-shutdown");
-                               else
-                                       log("warn", "Unable to close outgoing s2s session to %s, no session:close()?!", remotehost);
-                               end
-                       end
-               end
-       end
-
-       log("info", "Shutdown status: Closing all server connections");
-       server.closeall();
-       
-       server.setquitting(true);
 end
 
 -- Are you ready? :)