Merge pull request #4514 from taosdata/feature/TD-2405
[TD-2405]<feature>: new option -C (--dump-config) for taos and -C for taosd to dump configuration
This commit is contained in:
commit
6248b98621
|
@ -16,12 +16,15 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tgrant.h"
|
#include "tgrant.h"
|
||||||
|
#include "tconfig.h"
|
||||||
#include "dnodeMain.h"
|
#include "dnodeMain.h"
|
||||||
|
|
||||||
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context);
|
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context);
|
||||||
static tsem_t exitSem;
|
static tsem_t exitSem;
|
||||||
|
|
||||||
int32_t main(int32_t argc, char *argv[]) {
|
int32_t main(int32_t argc, char *argv[]) {
|
||||||
|
int dump_config = 0;
|
||||||
|
|
||||||
// Set global configuration file
|
// Set global configuration file
|
||||||
for (int32_t i = 1; i < argc; ++i) {
|
for (int32_t i = 1; i < argc; ++i) {
|
||||||
if (strcmp(argv[i], "-c") == 0) {
|
if (strcmp(argv[i], "-c") == 0) {
|
||||||
|
@ -35,6 +38,8 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
printf("'-c' requires a parameter, default:%s\n", configDir);
|
printf("'-c' requires a parameter, default:%s\n", configDir);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
} else if (strcmp(argv[i], "-C") == 0) {
|
||||||
|
dump_config = 1;
|
||||||
} else if (strcmp(argv[i], "-V") == 0) {
|
} else if (strcmp(argv[i], "-V") == 0) {
|
||||||
#ifdef _ACCT
|
#ifdef _ACCT
|
||||||
char *versionStr = "enterprise";
|
char *versionStr = "enterprise";
|
||||||
|
@ -87,6 +92,20 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 != dump_config) {
|
||||||
|
tscEmbedded = 1;
|
||||||
|
taosInitGlobalCfg();
|
||||||
|
taosReadGlobalLogCfg();
|
||||||
|
|
||||||
|
if (!taosReadGlobalCfg()) {
|
||||||
|
printf("TDengine read global config failed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosDumpGlobalCfg();
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
if (tsem_init(&exitSem, 0, 0) != 0) {
|
if (tsem_init(&exitSem, 0, 0) != 0) {
|
||||||
printf("failed to create exit semphore\n");
|
printf("failed to create exit semphore\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
|
@ -45,6 +45,7 @@ typedef struct SShellArguments {
|
||||||
char* timezone;
|
char* timezone;
|
||||||
bool is_raw_time;
|
bool is_raw_time;
|
||||||
bool is_use_passwd;
|
bool is_use_passwd;
|
||||||
|
bool dump_config;
|
||||||
char file[TSDB_FILENAME_LEN];
|
char file[TSDB_FILENAME_LEN];
|
||||||
char dir[TSDB_FILENAME_LEN];
|
char dir[TSDB_FILENAME_LEN];
|
||||||
int threadNum;
|
int threadNum;
|
||||||
|
|
|
@ -39,6 +39,7 @@ static struct argp_option options[] = {
|
||||||
{"user", 'u', "USER", 0, "The user name to use when connecting to the server."},
|
{"user", 'u', "USER", 0, "The user name to use when connecting to the server."},
|
||||||
{"user", 'A', "Auth", 0, "The user auth to use when connecting to the server."},
|
{"user", 'A', "Auth", 0, "The user auth to use when connecting to the server."},
|
||||||
{"config-dir", 'c', "CONFIG_DIR", 0, "Configuration directory."},
|
{"config-dir", 'c', "CONFIG_DIR", 0, "Configuration directory."},
|
||||||
|
{"dump-config", 'C', 0, 0, "Dump configuration."},
|
||||||
{"commands", 's', "COMMANDS", 0, "Commands to run without enter the shell."},
|
{"commands", 's', "COMMANDS", 0, "Commands to run without enter the shell."},
|
||||||
{"raw-time", 'r', 0, 0, "Output time as uint64_t."},
|
{"raw-time", 'r', 0, 0, "Output time as uint64_t."},
|
||||||
{"file", 'f', "FILE", 0, "Script to run without enter the shell."},
|
{"file", 'f', "FILE", 0, "Script to run without enter the shell."},
|
||||||
|
@ -96,6 +97,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||||
tstrncpy(configDir, full_path.we_wordv[0], TSDB_FILENAME_LEN);
|
tstrncpy(configDir, full_path.we_wordv[0], TSDB_FILENAME_LEN);
|
||||||
wordfree(&full_path);
|
wordfree(&full_path);
|
||||||
break;
|
break;
|
||||||
|
case 'C':
|
||||||
|
arguments->dump_config = true;
|
||||||
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
arguments->commands = arg;
|
arguments->commands = arg;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
|
#include "tconfig.h"
|
||||||
#include "tnettest.h"
|
#include "tnettest.h"
|
||||||
|
|
||||||
pthread_t pid;
|
pthread_t pid;
|
||||||
|
@ -58,6 +59,7 @@ SShellArguments args = {
|
||||||
.timezone = NULL,
|
.timezone = NULL,
|
||||||
.is_raw_time = false,
|
.is_raw_time = false,
|
||||||
.is_use_passwd = false,
|
.is_use_passwd = false,
|
||||||
|
.dump_config = false,
|
||||||
.file = "\0",
|
.file = "\0",
|
||||||
.dir = "\0",
|
.dir = "\0",
|
||||||
.threadNum = 5,
|
.threadNum = 5,
|
||||||
|
@ -78,6 +80,19 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
shellParseArgument(argc, argv, &args);
|
shellParseArgument(argc, argv, &args);
|
||||||
|
|
||||||
|
if (args.dump_config) {
|
||||||
|
taosInitGlobalCfg();
|
||||||
|
taosReadGlobalLogCfg();
|
||||||
|
|
||||||
|
if (!taosReadGlobalCfg()) {
|
||||||
|
printf("TDengine read global config failed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosDumpGlobalCfg();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (args.netTestRole && args.netTestRole[0] != 0) {
|
if (args.netTestRole && args.netTestRole[0] != 0) {
|
||||||
taos_init();
|
taos_init();
|
||||||
taosNetTest(args.netTestRole, args.host, args.port, args.pktLen);
|
taosNetTest(args.netTestRole, args.host, args.port, args.pktLen);
|
||||||
|
|
|
@ -35,6 +35,8 @@ void printHelp() {
|
||||||
printf("%s%s%s\n", indent, indent, "The user auth to use when connecting to the server.");
|
printf("%s%s%s\n", indent, indent, "The user auth to use when connecting to the server.");
|
||||||
printf("%s%s\n", indent, "-c");
|
printf("%s%s\n", indent, "-c");
|
||||||
printf("%s%s%s\n", indent, indent, "Configuration directory.");
|
printf("%s%s%s\n", indent, indent, "Configuration directory.");
|
||||||
|
printf("%s%s\n", indent, "-C");
|
||||||
|
printf("%s%s%s\n", indent, indent, "Dump configuration.");
|
||||||
printf("%s%s\n", indent, "-s");
|
printf("%s%s\n", indent, "-s");
|
||||||
printf("%s%s%s\n", indent, indent, "Commands to run without enter the shell.");
|
printf("%s%s%s\n", indent, indent, "Commands to run without enter the shell.");
|
||||||
printf("%s%s\n", indent, "-r");
|
printf("%s%s\n", indent, "-r");
|
||||||
|
@ -104,6 +106,8 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
|
||||||
fprintf(stderr, "Option -c requires an argument\n");
|
fprintf(stderr, "Option -c requires an argument\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
} else if (strcmp(argv[i], "-C") == 0) {
|
||||||
|
arguments->dump_config = true;
|
||||||
} else if (strcmp(argv[i], "-s") == 0) {
|
} else if (strcmp(argv[i], "-s") == 0) {
|
||||||
if (i < argc - 1) {
|
if (i < argc - 1) {
|
||||||
arguments->commands = argv[++i];
|
arguments->commands = argv[++i];
|
||||||
|
|
|
@ -78,6 +78,7 @@ extern char * tsCfgStatusStr[];
|
||||||
void taosReadGlobalLogCfg();
|
void taosReadGlobalLogCfg();
|
||||||
bool taosReadGlobalCfg();
|
bool taosReadGlobalCfg();
|
||||||
void taosPrintGlobalCfg();
|
void taosPrintGlobalCfg();
|
||||||
|
void taosDumpGlobalCfg();
|
||||||
|
|
||||||
void taosInitConfigOption(SGlobalCfg cfg);
|
void taosInitConfigOption(SGlobalCfg cfg);
|
||||||
SGlobalCfg * taosGetConfigOption(const char *option);
|
SGlobalCfg * taosGetConfigOption(const char *option);
|
||||||
|
|
|
@ -397,3 +397,57 @@ void taosPrintGlobalCfg() {
|
||||||
|
|
||||||
taosPrintOsInfo();
|
taosPrintOsInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void taosDumpCfg(SGlobalCfg *cfg) {
|
||||||
|
int optionLen = (int)strlen(cfg->option);
|
||||||
|
int blankLen = TSDB_CFG_PRINT_LEN - optionLen;
|
||||||
|
blankLen = blankLen < 0 ? 0 : blankLen;
|
||||||
|
|
||||||
|
char blank[TSDB_CFG_PRINT_LEN];
|
||||||
|
memset(blank, ' ', TSDB_CFG_PRINT_LEN);
|
||||||
|
blank[blankLen] = 0;
|
||||||
|
|
||||||
|
switch (cfg->valType) {
|
||||||
|
case TAOS_CFG_VTYPE_INT16:
|
||||||
|
printf(" %s:%s%d%s\n", cfg->option, blank, *((int16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||||
|
break;
|
||||||
|
case TAOS_CFG_VTYPE_INT32:
|
||||||
|
printf(" %s:%s%d%s\n", cfg->option, blank, *((int32_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||||
|
break;
|
||||||
|
case TAOS_CFG_VTYPE_FLOAT:
|
||||||
|
printf(" %s:%s%f%s\n", cfg->option, blank, *((float *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||||
|
break;
|
||||||
|
case TAOS_CFG_VTYPE_STRING:
|
||||||
|
case TAOS_CFG_VTYPE_IPSTR:
|
||||||
|
case TAOS_CFG_VTYPE_DIRECTORY:
|
||||||
|
printf(" %s:%s%s%s\n", cfg->option, blank, (char *)cfg->ptr, tsGlobalUnit[cfg->unitType]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void taosDumpGlobalCfg() {
|
||||||
|
printf("taos global config:\n");
|
||||||
|
printf("==================================\n");
|
||||||
|
for (int i = 0; i < tsGlobalConfigNum; ++i) {
|
||||||
|
SGlobalCfg *cfg = tsGlobalConfig + i;
|
||||||
|
if (tscEmbedded == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue;
|
||||||
|
if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue;
|
||||||
|
if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW)) continue;
|
||||||
|
|
||||||
|
taosDumpCfg(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\ntaos local config:\n");
|
||||||
|
printf("==================================\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < tsGlobalConfigNum; ++i) {
|
||||||
|
SGlobalCfg *cfg = tsGlobalConfig + i;
|
||||||
|
if (tscEmbedded == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue;
|
||||||
|
if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue;
|
||||||
|
if (cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW) continue;
|
||||||
|
|
||||||
|
taosDumpCfg(cfg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue