Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/traffic_server/traffic_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

#include <syslog.h>
#include <algorithm>
#include <atomic>
#include <list>
#include <string>

Expand Down Expand Up @@ -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<bool> ports_are_open = false;
static std::atomic<bool> 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.
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions tests/gold_tests/autest-site/trafficserver.test.ext
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion tests/gold_tests/autest-site/when.test.ext
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down