Skip to content

Commit eac31a4

Browse files
danobijpeach
authored andcommitted
TS-4399: Management API messes up proxy options.
TS-4399: Management API breaks diagnostic log rotation TS-4400: TSProxyStateSet persist cache clearing across restart The two issues above are related in that they both deal with the management API not correctly handling proxy flags. For TS-4399, it was because the management API was not aware of traffic_manager setting extra proxy options. This was fixed by providing CoreAPI a callback to get extra proxy options from traffic_manager. For TS-4400, it was because the management API was not properly clearing optional flags between proxy reboots. This was fixed by resetting the proxy options before each reboot. This patch centralizes where traffic_server starts to inside CoreAPI's ProxyStateSet. This is good because we reduce the number of places we deal with traffic_server options. Everything is simply handled by the proxy_options_callback. We use proxy_options as persistent proxy options storage. Then have lmgmt->startProxy() take in an argument for one-time flags. This closes #1073.
1 parent 2639f09 commit eac31a4

File tree

4 files changed

+34
-39
lines changed

4 files changed

+34
-39
lines changed

cmd/traffic_manager/traffic_manager.cc

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "FileManager.h"
3838
#include "ts/I_Layout.h"
3939
#include "ts/I_Version.h"
40+
#include "ts/TextBuffer.h"
4041
#include "DiagsConfig.h"
4142
#include "HTTP.h"
4243
#include "CoreAPI.h"
@@ -610,33 +611,27 @@ main(int argc, const char **argv)
610611

611612
/* Update cmd line overrides/environmental overrides/etc */
612613
if (tsArgs) { /* Passed command line args for proxy */
613-
ats_free(lmgmt->proxy_options);
614-
lmgmt->proxy_options = tsArgs;
615-
mgmt_log("[main] Traffic Server Args: '%s'\n", lmgmt->proxy_options);
614+
lmgmt->proxy_options = ats_strdup(tsArgs);
616615
}
617616

618-
// we must pass in bind_stdout and bind_stderr values to TS
619-
// we do it so TS is able to create BaseLogFiles for each value
620-
if (*bind_stdout != 0) {
621-
size_t l = strlen(lmgmt->proxy_options);
622-
size_t n = 3 /* " --" */
623-
+ sizeof(TM_OPT_BIND_STDOUT) /* nul accounted for here */
624-
+ 1 /* space */
625-
+ strlen(bind_stdout);
626-
lmgmt->proxy_options = static_cast<char *>(ats_realloc(lmgmt->proxy_options, n + l));
627-
snprintf(lmgmt->proxy_options + l, n, " --%s %s", TM_OPT_BIND_STDOUT, bind_stdout);
617+
// TS needs to be started up with the same outputlog bindings each time,
618+
// so we append the outputlog location to the persistent proxy options
619+
//
620+
// TS needs them to be able to create BaseLogFiles for each value
621+
textBuffer args(1024);
622+
623+
if (*bind_stdout) {
624+
const char *space = args.empty() ? "" : " ";
625+
args.format("%s%s %s", space, "--" TM_OPT_BIND_STDOUT, bind_stdout);
628626
}
629627

630-
if (*bind_stderr != 0) {
631-
size_t l = strlen(lmgmt->proxy_options);
632-
size_t n = 3 /* space dash dash */
633-
+ sizeof(TM_OPT_BIND_STDERR) /* nul accounted for here */
634-
+ 1 /* space */
635-
+ strlen(bind_stderr);
636-
lmgmt->proxy_options = static_cast<char *>(ats_realloc(lmgmt->proxy_options, n + l));
637-
snprintf(lmgmt->proxy_options + l, n, " --%s %s", TM_OPT_BIND_STDERR, bind_stderr);
628+
if (*bind_stderr) {
629+
const char *space = args.empty() ? "" : " ";
630+
args.format("%s%s %s", space, "--" TM_OPT_BIND_STDERR, bind_stderr);
638631
}
639632

633+
lmgmt->proxy_options = args.release();
634+
640635
if (proxy_port) {
641636
HttpProxyPort::loadValue(lmgmt->m_proxy_ports, proxy_port);
642637
}
@@ -812,7 +807,7 @@ main(int argc, const char **argv)
812807
} else {
813808
sleep_time = 1;
814809
}
815-
if (lmgmt->startProxy()) {
810+
if (ProxyStateSet(TS_PROXY_ON, TS_CACHE_CLEAR_NONE) == TS_ERR_OKAY) {
816811
just_started = 0;
817812
sleep_time = 0;
818813
} else {

mgmt/LocalManager.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ LocalManager::LocalManager(bool proxy_on) : BaseManager(), run_proxy(proxy_on),
241241
process_server_timeout_msecs = REC_readInteger("proxy.config.lm.pserver_timeout_msecs", &found);
242242
proxy_name = REC_readString("proxy.config.proxy_name", &found);
243243
proxy_binary = REC_readString("proxy.config.proxy_binary", &found);
244-
proxy_options = REC_readString("proxy.config.proxy_binary_opts", &found);
245244
env_prep = REC_readString("proxy.config.env_prep", &found);
245+
proxy_options = NULL;
246246

247247
// Calculate proxy_binary from the absolute bin_path
248248
absolute_proxy_binary = Layout::relative_to(bindir, proxy_binary);
@@ -853,9 +853,13 @@ LocalManager::processEventQueue()
853853
/*
854854
* startProxy()
855855
* Function fires up a proxy process.
856+
*
857+
* Args:
858+
* onetime_options: one time options that traffic_server should be started with (ie
859+
* these options do not persist across reboots)
856860
*/
857861
bool
858-
LocalManager::startProxy()
862+
LocalManager::startProxy(const char *onetime_options)
859863
{
860864
if (proxy_launch_outstanding) {
861865
return false;
@@ -924,8 +928,13 @@ LocalManager::startProxy()
924928
Vec<char> real_proxy_options;
925929

926930
real_proxy_options.append(proxy_options, strlen(proxy_options));
931+
if (onetime_options && *onetime_options) {
932+
real_proxy_options.append(" ", strlen(" "));
933+
real_proxy_options.append(onetime_options, strlen(onetime_options));
934+
}
927935

928-
if (!strstr(proxy_options, MGMT_OPT)) { // Make sure we're starting the proxy in mgmt mode
936+
// Make sure we're starting the proxy in mgmt mode
937+
if (strstr(proxy_options, MGMT_OPT) == 0 && strstr(onetime_options, MGMT_OPT) == 0) {
929938
real_proxy_options.append(" ", strlen(" "));
930939
real_proxy_options.append(MGMT_OPT, sizeof(MGMT_OPT) - 1);
931940
}

mgmt/LocalManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class LocalManager : public BaseManager
7474
void signalAlarm(int alarm_id, const char *desc = NULL, const char *ip = NULL);
7575

7676
void processEventQueue();
77-
bool startProxy();
77+
bool startProxy(const char *onetime_options);
7878
void listenForProxy();
7979
void bindProxyPort(HttpProxyPort &);
8080
void closeProxyPorts();
@@ -108,7 +108,7 @@ class LocalManager : public BaseManager
108108
char *absolute_proxy_binary;
109109
char *proxy_name;
110110
char *proxy_binary;
111-
char *proxy_options;
111+
char *proxy_options; // These options should persist across proxy reboots
112112
char *env_prep;
113113

114114
int process_server_sockfd;

mgmt/api/CoreAPI.cc

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ ProxyStateGet()
153153
TSMgmtError
154154
ProxyStateSet(TSProxyStateT state, TSCacheClearT clear)
155155
{
156-
int i = 0;
157156
char tsArgs[MAX_BUF_SIZE];
158157
char *proxy_options;
159158

@@ -184,24 +183,16 @@ ProxyStateSet(TSProxyStateT state, TSCacheClearT clear)
184183
ink_strlcat(tsArgs, " -k", sizeof(tsArgs));
185184
}
186185

187-
if (strlen(tsArgs) > 0) { /* Passed command line args for proxy */
188-
ats_free(lmgmt->proxy_options);
189-
lmgmt->proxy_options = ats_strdup(tsArgs);
190-
mgmt_log("[ProxyStateSet] Traffic Server Args: '%s'\n", lmgmt->proxy_options);
191-
}
186+
mgmt_log("[ProxyStateSet] Traffic Server Args: '%s %s'\n", lmgmt->proxy_options ? lmgmt->proxy_options : "", tsArgs);
192187

193188
lmgmt->run_proxy = true;
194189
lmgmt->listenForProxy();
195-
196-
do {
197-
mgmt_sleep_sec(1);
198-
} while (i++ < 20 && (lmgmt->proxy_running == 0));
199-
200-
if (!lmgmt->processRunning()) {
190+
if (!lmgmt->startProxy(tsArgs)) {
201191
goto Lerror;
202192
}
203193

204194
break;
195+
205196
default:
206197
goto Lerror;
207198
}

0 commit comments

Comments
 (0)