diff --git a/src/traffic_server/traffic_server.cc b/src/traffic_server/traffic_server.cc index 6153edd22a1..80f5aebbe1d 100644 --- a/src/traffic_server/traffic_server.cc +++ b/src/traffic_server/traffic_server.cc @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -173,6 +174,9 @@ static int poll_timeout = -1; // No value set. static int cmd_disable_freelist = 0; static bool signal_received[NSIG]; +static std::atomic ports_are_open = false; +static std::atomic cache_is_initialized = false; + // 1: delay listen, wait for cache. // 0: Do not delay, start listen ASAP. // -1: cache is already initialized, don't delay. @@ -709,7 +713,8 @@ CB_After_Cache_Init() APIHook *hook; int start; - start = ink_atomic_swap(&delay_listen_for_cache_p, -1); + start = ink_atomic_swap(&delay_listen_for_cache_p, -1); + cache_is_initialized = true; #if TS_ENABLE_FIPS == 0 // Check for cache BC after the cache is initialized and before listen, if possible. @@ -726,6 +731,7 @@ CB_After_Cache_Init() if (1 == start) { Debug("http_listen", "Delayed listen enable, cache initialization finished"); start_HttpProxyServer(); + ports_are_open = true; } time_t cache_ready_at = time(nullptr); @@ -737,6 +743,9 @@ CB_After_Cache_Init() hook->invoke(TS_EVENT_LIFECYCLE_CACHE_READY, nullptr); hook = hook->next(); } + if (ports_are_open) { + Note("traffic server initialized"); + } } void @@ -2094,7 +2103,9 @@ main(int /* argc ATS_UNUSED */, const char **argv) if (delay_p && ink_atomic_cas(&delay_listen_for_cache_p, 0, 1)) { Debug("http_listen", "Delaying listen, waiting for cache initialization"); } else { + Debug("http_listen", "Not delaying listen"); start_HttpProxyServer(); // PORTS_READY_HOOK called from in here + ports_are_open = true; } } // Plugins can register their own configuration names so now after they've done that @@ -2125,6 +2136,9 @@ main(int /* argc ATS_UNUSED */, const char **argv) ink_set_thread_name("[TS_MAIN]"); + if (ports_are_open && cache_is_initialized) { + Note("traffic server initialized"); + } Note("traffic server running"); #if TS_HAS_TESTS diff --git a/tests/gold_tests/autest-site/trafficserver.test.ext b/tests/gold_tests/autest-site/trafficserver.test.ext index 779f183e373..4c974c9a35e 100755 --- a/tests/gold_tests/autest-site/trafficserver.test.ext +++ b/tests/gold_tests/autest-site/trafficserver.test.ext @@ -281,10 +281,9 @@ def MakeATSProcess(obj, name, command='traffic_server', select_ports=True, enabl get_port(p, "manager_port") get_port(p, "admin_port") - if enable_tls: - p.Ready = When.PortsOpen([p.Variables.port, p.Variables.ssl_port]) - else: - p.Ready = When.PortOpen(p.Variables.port) + # The following message was added so that tests and users can know when + # Traffic Server is ready to both receive and optimize traffic. + p.Ready = When.FileContains(p.Disk.diags_log.AbsPath, "NOTE: traffic server initialized") if select_ports: # default config diff --git a/tests/gold_tests/autest-site/when.test.ext b/tests/gold_tests/autest-site/when.test.ext index d44c9ba09cc..b93e8980232 100644 --- a/tests/gold_tests/autest-site/when.test.ext +++ b/tests/gold_tests/autest-site/when.test.ext @@ -19,14 +19,33 @@ When extensions. from autest.api import AddWhenFunction import hosts.output as host +import os def FileContains(haystack, needle): + """ + Return whether the file haystack contains the string needle. + + Args: + haystack (str): The path to the file to be inspected. + needle (str): The content to look for in haystack. + + Returns: + True if the haystack exists as a file and contains needle, False + otherwise. + """ + if not os.path.exists(haystack): + host.WriteDebug( + ['FileContains', 'when'], + "Testing for file content '{0}' in file '{1}': file does not exist".format( + needle, haystack)) + return False + with open(haystack) as f: result = needle in f.read() host.WriteDebug( - ['FileExists', 'when'], + ['FileContains', 'when'], "Testing for file content '{0}' in '{1}' : {2}".format( needle, haystack, result))