You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2016/05/02 18:08:19 UTC
[trafficserver] 03/04: TS-4380: Initial traffic_ctl support for
server start/stop.
This is an automated email from the ASF dual-hosted git repository.
jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git
commit ebdcea436ec273e25a76df3b770a264d450f318d
Author: James Peach <jp...@apache.org>
AuthorDate: Sun Apr 24 14:30:56 2016 -0700
TS-4380: Initial traffic_ctl support for server start/stop.
Implement a basic version of the "server start" and "server stop"
subcommands for traffic_ctl. This brings feature parity with
traffic_line.
---
cmd/traffic_ctl/server.cc | 67 +++++++++++++++++++++++++++++++++++++++++------
1 file changed, 59 insertions(+), 8 deletions(-)
diff --git a/cmd/traffic_ctl/server.cc b/cmd/traffic_ctl/server.cc
index 70db76f..0b7115f 100644
--- a/cmd/traffic_ctl/server.cc
+++ b/cmd/traffic_ctl/server.cc
@@ -26,17 +26,17 @@
static int drain = 0;
static int manager = 0;
-const ArgumentDescription opts[] = {
- {"drain", '-', "Wait for client connections to drain before restarting", "F", &drain, NULL, NULL},
- {"manager", '-', "Restart traffic_manager as well as traffic_server", "F", &manager, NULL, NULL},
-};
-
static int
restart(unsigned argc, const char **argv, unsigned flags)
{
TSMgmtError error;
const char *usage = (flags & TS_RESTART_OPT_CLUSTER) ? "cluster restart [OPTIONS]" : "server restart [OPTIONS]";
+ const ArgumentDescription opts[] = {
+ {"drain", '-', "Wait for client connections to drain before restarting", "F", &drain, NULL, NULL},
+ {"manager", '-', "Restart traffic_manager as well as traffic_server", "F", &manager, NULL, NULL},
+ };
+
if (!CtrlProcessArguments(argc, argv, opts, countof(opts)) || n_file_arguments != 0) {
return CtrlCommandUsage(usage, opts, countof(opts));
}
@@ -116,6 +116,57 @@ server_status(unsigned argc, const char **argv)
return CTRL_EX_OK;
}
+static int
+server_stop(unsigned argc, const char **argv)
+{
+ TSMgmtError error;
+
+ // I am not sure whether it really makes sense to add the --drain option here.
+ // TSProxyStateSet() is a synchronous API, returning only after the proxy has
+ // been shut down. However, draining can take a long time and we don't want
+ // to wait for it. Maybe the right approach is to make the stop async.
+ if (!CtrlProcessArguments(argc, argv, NULL, 0) || n_file_arguments != 0) {
+ return CtrlCommandUsage("server stop");
+ }
+
+ error = TSProxyStateSet(TS_PROXY_OFF, TS_CACHE_CLEAR_NONE);
+ if (error != TS_ERR_OKAY) {
+ CtrlMgmtError(error, "server stop failed");
+ return CTRL_EX_ERROR;
+ }
+
+ return CTRL_EX_OK;
+}
+
+static int
+server_start(unsigned argc, const char **argv)
+{
+ TSMgmtError error;
+ int cache = 0;
+ int hostdb = 0;
+ unsigned clear = TS_CACHE_CLEAR_NONE;
+
+ const ArgumentDescription opts[] = {
+ {"clear-cache", '-', "Clear the disk cache on startup", "F", &cache, NULL, NULL},
+ {"clear-hostdb", '-', "Clear the DNS cache on startup", "F", &hostdb, NULL, NULL},
+ };
+
+ if (!CtrlProcessArguments(argc, argv, opts, countof(opts)) || n_file_arguments != 0) {
+ return CtrlCommandUsage("server start [OPTIONS]", opts, countof(opts));
+ }
+
+ clear |= cache ? TS_CACHE_CLEAR_CACHE : TS_CACHE_CLEAR_NONE;
+ clear |= hostdb ? TS_CACHE_CLEAR_HOSTDB : TS_CACHE_CLEAR_NONE;
+
+ error = TSProxyStateSet(TS_PROXY_ON, clear);
+ if (error != TS_ERR_OKAY) {
+ CtrlMgmtError(error, "server start failed");
+ return CTRL_EX_ERROR;
+ }
+
+ return CTRL_EX_OK;
+}
+
int
subcommand_cluster(unsigned argc, const char **argv)
{
@@ -131,11 +182,11 @@ int
subcommand_server(unsigned argc, const char **argv)
{
const subcommand commands[] = {
- {server_restart, "restart", "Restart Traffic Server"},
{server_backtrace, "backtrace", "Show a full stack trace of the traffic_server process"},
+ {server_restart, "restart", "Restart Traffic Server"},
+ {server_start, "start", "Start the proxy"},
{server_status, "status", "Show the proxy status"},
-
- /* XXX do the 'shutdown' and 'startup' commands make sense? */
+ {server_stop, "stop", "Stop the proxy"},
};
return CtrlGenericSubcommand("server", commands, countof(commands), argc, argv);
--
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.