]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: protocol: add protocol_stop_now() to instant-stop listeners
authorWilly Tarreau <w@1wt.eu>
Wed, 7 Oct 2020 14:50:49 +0000 (16:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2020 16:29:04 +0000 (18:29 +0200)
This will instantly stop all listeners except those which belong to
a proxy configured with a grace time. This means that UDP listeners,
and peers will also be stopped when called this way.

include/haproxy/protocol.h
src/protocol.c

index a752f98d96f8ebb98eb0f7b236744b41bb25d531..81f4d5bdbb93c17c22e5844d3fdd4cbbeeb68da5 100644 (file)
@@ -50,6 +50,14 @@ int protocol_bind_all(int verbose);
  */
 int protocol_unbind_all(void);
 
+/* stops all listeners of all registered protocols, except when the belong to a
+ * proxy configured with a grace time. This will normally catch every single
+ * listener, all protocols included, and the grace ones will have to be handled
+ * by the proxy stopping loop. This is to be used during soft_stop() only. It
+ * does not return any error.
+ */
+void protocol_stop_now(void);
+
 /* pauses all listeners of all registered protocols. This is typically
  * used on SIG_TTOU to release all listening sockets for the time needed to
  * try to bind a new process. The listeners enter LI_PAUSED. It returns
index c0a00904ca85540087434c319c45a7b8322dbf80..82deaad4f8a2edd7a69a52cdd782d3cf77f653a5 100644 (file)
@@ -151,6 +151,26 @@ int protocol_unbind_all(void)
        return err;
 }
 
+/* stops all listeners of all registered protocols, except when the belong to a
+ * proxy configured with a grace time. This will normally catch every single
+ * listener, all protocols included, and the grace ones will have to be handled
+ * by the proxy stopping loop. This is to be used during soft_stop() only. It
+ * does not return any error.
+ */
+void protocol_stop_now(void)
+{
+       struct protocol *proto;
+       struct listener *listener, *lback;
+
+       HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
+       list_for_each_entry(proto, &protocols, list) {
+               list_for_each_entry_safe(listener, lback, &proto->receivers, rx.proto_list)
+                       if (!listener->bind_conf->frontend->grace)
+                               stop_listener(listener, 0, 1, 0);
+       }
+       HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
+}
+
 /* pauses all listeners of all registered protocols. This is typically
  * used on SIG_TTOU to release all listening sockets for the time needed to
  * try to bind a new process. The listeners enter LI_PAUSED. It returns