summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2020-10-07 16:50:49 +0200
committerWilly Tarreau <w@1wt.eu>2020-10-07 19:42:32 +0200
commitaac15f6a2a1d78542627630f58da09d29f2ab60f (patch)
tree0c904d30afd3ec5e5248104bfcb93f8b3959512c
parent7e3196b1560469a9ed16b4898797514720778264 (diff)
downloadhaproxy-aac15f6a2a1d78542627630f58da09d29f2ab60f.tar.gz
MINOR: protocol: add protocol_stop_now() to instant-stop listeners
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.
-rw-r--r--include/haproxy/protocol.h8
-rw-r--r--src/protocol.c20
2 files changed, 28 insertions, 0 deletions
diff --git a/include/haproxy/protocol.h b/include/haproxy/protocol.h
index a752f98d9..81f4d5bdb 100644
--- a/include/haproxy/protocol.h
+++ b/include/haproxy/protocol.h
@@ -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
diff --git a/src/protocol.c b/src/protocol.c
index c0a00904c..82deaad4f 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -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