You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by du...@apache.org on 2018/12/21 16:56:10 UTC

[trafficserver] branch master updated: shutdown hook

This is an automated email from the ASF dual-hosted git repository.

duke8253 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new b9a9fc4  shutdown hook
b9a9fc4 is described below

commit b9a9fc4c5730e5af5e36db5a1a43f30bde51ab26
Author: Fei Deng <du...@gmail.com>
AuthorDate: Wed Dec 19 15:14:51 2018 -0600

    shutdown hook
---
 doc/developer-guide/api/functions/TSLifecycleHookAdd.en.rst | 6 ++++++
 include/ts/apidefs.h.in                                     | 8 ++++++++
 proxy/http/HttpDebugNames.cc                                | 2 ++
 src/traffic_server/traffic_server.cc                        | 6 ++++++
 4 files changed, 22 insertions(+)

diff --git a/doc/developer-guide/api/functions/TSLifecycleHookAdd.en.rst b/doc/developer-guide/api/functions/TSLifecycleHookAdd.en.rst
index bac552b..82b22d4 100644
--- a/doc/developer-guide/api/functions/TSLifecycleHookAdd.en.rst
+++ b/doc/developer-guide/api/functions/TSLifecycleHookAdd.en.rst
@@ -105,6 +105,12 @@ Types
       Invoked with the event :c:data:`TS_EVENT_LIFECYCLE_TASK_THREADS_READY` and ``NULL``
       data.
 
+   .. cpp:enumerator:: TS_LIFECYCLE_SHUTDOWN_HOOK
+
+      Called after |TS| receiving a shutdown signal, such as SIGTERM.
+
+      Invoked with the event :c:data:`TS_EVENT_LIFECYCLE_SHUTDOWN` and ``NULL`` data.
+
 .. c:type:: TSPluginMsg
 
    The format of the data for the plugin message event :c:data:`TS_EVENT_LIFECYCLE_MSG`.
diff --git a/include/ts/apidefs.h.in b/include/ts/apidefs.h.in
index 8b74969..ad5be0b 100644
--- a/include/ts/apidefs.h.in
+++ b/include/ts/apidefs.h.in
@@ -360,6 +360,12 @@ typedef enum {
 
       Event: TS_EVENT_LIFECYCLE_TASK_THREADS_READY
 
+    TS_LIFECYCLE_SHUTDOWN_HOOK
+
+      called once, after receiving a shutdown signal, such as SIGTERM.
+
+      Event: TS_EVENT_LIFECYCLE_SHUTDOWN
+
     Ordering guarantees:
 
     - TS_LIFECYCLE_PORTS_INITIALIZED_HOOK before TS_LIFECYCLE_PORTS_READY_HOOK.
@@ -375,6 +381,7 @@ typedef enum {
   TS_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED_HOOK,
   TS_LIFECYCLE_MSG_HOOK,
   TS_LIFECYCLE_TASK_THREADS_READY_HOOK,
+  TS_LIFECYCLE_SHUTDOWN_HOOK,
   TS_LIFECYCLE_LAST_HOOK
 } TSLifecycleHookID;
 
@@ -461,6 +468,7 @@ typedef enum {
   TS_EVENT_LIFECYCLE_SERVER_SSL_CTX_INITIALIZED = 60021,
   TS_EVENT_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED = 60022,
   TS_EVENT_LIFECYCLE_TASK_THREADS_READY         = 60027,
+  TS_EVENT_LIFECYCLE_SHUTDOWN                   = 60028,
   TS_EVENT_VCONN_START                          = 60023,
   TS_EVENT_VCONN_PRE_ACCEPT                     = TS_EVENT_VCONN_START, // Deprecated but still compatible
   TS_EVENT_VCONN_CLOSE                          = 60026,
diff --git a/proxy/http/HttpDebugNames.cc b/proxy/http/HttpDebugNames.cc
index 576e75a..c76ef0e 100644
--- a/proxy/http/HttpDebugNames.cc
+++ b/proxy/http/HttpDebugNames.cc
@@ -347,6 +347,8 @@ HttpDebugNames::get_event_name(int event)
     return "TS_EVENT_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED";
   case TS_EVENT_LIFECYCLE_TASK_THREADS_READY:
     return "TS_EVENT_LIFECYCLE_TASK_THREADS_READY";
+  case TS_EVENT_LIFECYCLE_SHUTDOWN:
+    return "TS_EVENT_LIFECYCLE_SHUTDOWN";
   case TS_EVENT_VCONN_START:
     return "TS_EVENT_VCONN_START";
   case TS_EVENT_VCONN_CLOSE:
diff --git a/src/traffic_server/traffic_server.cc b/src/traffic_server/traffic_server.cc
index 2d5f337..b2753c8 100644
--- a/src/traffic_server/traffic_server.cc
+++ b/src/traffic_server/traffic_server.cc
@@ -219,6 +219,12 @@ struct AutoStopCont : public Continuation {
   int
   mainEvent(int /* event */, Event * /* e */)
   {
+    APIHook *hook = lifecycle_hooks->get(TS_LIFECYCLE_SHUTDOWN_HOOK);
+    while (hook) {
+      hook->invoke(TS_EVENT_LIFECYCLE_SHUTDOWN, nullptr);
+      hook = hook->next();
+    }
+
     pmgmt->stop();
     shutdown_event_system = true;
     delete this;