⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctdb.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
	data.dptr = (uint8_t *)&options.vnn;	data.dsize = sizeof(uint32_t);	ret = ctdb_send_message(ctdb, recmaster, CTDB_SRVID_UNBAN_NODE, data);	if (ret != 0) {		DEBUG(0,("Failed to tell the recmaster to unban node %u\n", options.vnn));		return -1;	}		return 0;}/*  shutdown a daemon */static int control_shutdown(struct ctdb_context *ctdb, int argc, const char **argv){	int ret;	ret = ctdb_ctrl_shutdown(ctdb, TIMELIMIT(), options.vnn);	if (ret != 0) {		printf("Unable to shutdown node %u\n", options.vnn);		return ret;	}	return 0;}/*  trigger a recovery */static int control_recover(struct ctdb_context *ctdb, int argc, const char **argv){	int ret;	ret = ctdb_ctrl_freeze(ctdb, TIMELIMIT(), options.vnn);	if (ret != 0) {		printf("Unable to freeze node\n");		return ret;	}	ret = ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.vnn, CTDB_RECOVERY_ACTIVE);	if (ret != 0) {		printf("Unable to set recovery mode\n");		return ret;	}	return 0;}/*  display monitoring mode of a remote node */static int control_getmonmode(struct ctdb_context *ctdb, int argc, const char **argv){	uint32_t monmode;	int ret;	ret = ctdb_ctrl_getmonmode(ctdb, TIMELIMIT(), options.vnn, &monmode);	if (ret != 0) {		printf("Unable to get monmode from node %u\n", options.vnn);		return ret;	}	printf("Monitoring mode:%s (%d)\n",monmode==CTDB_MONITORING_ACTIVE?"ACTIVE":"DISABLED",monmode);	return 0;}/*  set the monitoring mode of a remote node */static int control_setmonmode(struct ctdb_context *ctdb, int argc, const char **argv){	uint32_t monmode;	int ret;	if (argc < 1) {		usage();	}	monmode = strtoul(argv[0], NULL, 0);	ret = ctdb_ctrl_setmonmode(ctdb, TIMELIMIT(), options.vnn, monmode);	if (ret != 0) {		printf("Unable to set monmode on node %u\n", options.vnn);		return ret;	}	return 0;}/*  display remote list of keys/data for a db */static int control_catdb(struct ctdb_context *ctdb, int argc, const char **argv){	const char *db_name;	struct ctdb_db_context *ctdb_db;	int ret;	if (argc < 1) {		usage();	}	db_name = argv[0];	ctdb_db = ctdb_attach(ctdb, db_name);	if (ctdb_db == NULL) {		DEBUG(0,("Unable to attach to database '%s'\n", db_name));		return -1;	}	/* traverse and dump the cluster tdb */	ret = ctdb_dump_db(ctdb_db, stdout);	if (ret == -1) {		printf("Unable to dump database\n");		return -1;	}	talloc_free(ctdb_db);	printf("Dumped %d records\n", ret);	return 0;}/*  display a list of the databases on a remote ctdb */static int control_getdbmap(struct ctdb_context *ctdb, int argc, const char **argv){	int i, ret;	struct ctdb_dbid_map *dbmap=NULL;	ret = ctdb_ctrl_getdbmap(ctdb, TIMELIMIT(), options.vnn, ctdb, &dbmap);	if (ret != 0) {		printf("Unable to get dbids from node %u\n", options.vnn);		return ret;	}	printf("Number of databases:%d\n", dbmap->num);	for(i=0;i<dbmap->num;i++){		const char *path;		const char *name;		ctdb_ctrl_getdbpath(ctdb, TIMELIMIT(), options.vnn, dbmap->dbids[i], ctdb, &path);		ctdb_ctrl_getdbname(ctdb, TIMELIMIT(), options.vnn, dbmap->dbids[i], ctdb, &name);		printf("dbid:0x%08x name:%s path:%s\n", dbmap->dbids[i], name, path);	}	return 0;}/*  ping a node */static int control_ping(struct ctdb_context *ctdb, int argc, const char **argv){	int ret;	struct timeval tv = timeval_current();	ret = ctdb_ctrl_ping(ctdb, options.vnn);	if (ret == -1) {		printf("Unable to get ping response from node %u\n", options.vnn);	} else {		printf("response from %u time=%.6f sec  (%d clients)\n", 		       options.vnn, timeval_elapsed(&tv), ret);	}	return 0;}/*  get a tunable */static int control_getvar(struct ctdb_context *ctdb, int argc, const char **argv){	const char *name;	uint32_t value;	int ret;	if (argc < 1) {		usage();	}	name = argv[0];	ret = ctdb_ctrl_get_tunable(ctdb, TIMELIMIT(), options.vnn, name, &value);	if (ret == -1) {		printf("Unable to get tunable variable '%s'\n", name);		return -1;	}	printf("%-19s = %u\n", name, value);	return 0;}/*  set a tunable */static int control_setvar(struct ctdb_context *ctdb, int argc, const char **argv){	const char *name;	uint32_t value;	int ret;	if (argc < 2) {		usage();	}	name = argv[0];	value = strtoul(argv[1], NULL, 0);	ret = ctdb_ctrl_set_tunable(ctdb, TIMELIMIT(), options.vnn, name, value);	if (ret == -1) {		printf("Unable to set tunable variable '%s'\n", name);		return -1;	}	return 0;}/*  list all tunables */static int control_listvars(struct ctdb_context *ctdb, int argc, const char **argv){	uint32_t count;	const char **list;	int ret, i;	ret = ctdb_ctrl_list_tunables(ctdb, TIMELIMIT(), options.vnn, ctdb, &list, &count);	if (ret == -1) {		printf("Unable to list tunable variables\n");		return -1;	}	for (i=0;i<count;i++) {		control_getvar(ctdb, 1, &list[i]);	}	talloc_free(list);		return 0;}/*  display debug level on a node */static int control_getdebug(struct ctdb_context *ctdb, int argc, const char **argv){	int ret;	uint32_t level;	ret = ctdb_ctrl_get_debuglevel(ctdb, options.vnn, &level);	if (ret != 0) {		printf("Unable to get debuglevel response from node %u\n", 		       options.vnn);	} else {		printf("Node %u is at debug level %u\n", options.vnn, level);	}	return 0;}/*  set debug level on a node or all nodes */static int control_setdebug(struct ctdb_context *ctdb, int argc, const char **argv){	int ret;	uint32_t level;	if (argc < 1) {		usage();	}	level = strtoul(argv[0], NULL, 0);	ret = ctdb_ctrl_set_debuglevel(ctdb, options.vnn, level);	if (ret != 0) {		printf("Unable to set debug level on node %u\n", options.vnn);	}	return 0;}/*  freeze a node */static int control_freeze(struct ctdb_context *ctdb, int argc, const char **argv){	int ret;	ret = ctdb_ctrl_freeze(ctdb, TIMELIMIT(), options.vnn);	if (ret != 0) {		printf("Unable to freeze node %u\n", options.vnn);	}			return 0;}/*  thaw a node */static int control_thaw(struct ctdb_context *ctdb, int argc, const char **argv){	int ret;	ret = ctdb_ctrl_thaw(ctdb, TIMELIMIT(), options.vnn);	if (ret != 0) {		printf("Unable to thaw node %u\n", options.vnn);	}			return 0;}/*  attach to a database */static int control_attach(struct ctdb_context *ctdb, int argc, const char **argv){	const char *db_name;	struct ctdb_db_context *ctdb_db;	if (argc < 1) {		usage();	}	db_name = argv[0];	ctdb_db = ctdb_attach(ctdb, db_name);	if (ctdb_db == NULL) {		DEBUG(0,("Unable to attach to database '%s'\n", db_name));		return -1;	}	return 0;}/*  dump memory usage */static int control_dumpmemory(struct ctdb_context *ctdb, int argc, const char **argv){	return ctdb_control(ctdb, options.vnn, 0, CTDB_CONTROL_DUMP_MEMORY,			    CTDB_CTRL_FLAG_NOREPLY, tdb_null, NULL, NULL, NULL, NULL, NULL);}static const struct {	const char *name;	int (*fn)(struct ctdb_context *, int, const char **);	bool auto_all;	const char *msg;	const char *args;} ctdb_commands[] = {	{ "status",          control_status,            true,  "show node status" },	{ "ping",            control_ping,              true,  "ping all nodes" },	{ "getvar",          control_getvar,            true,  "get a tunable variable",               "<name>"},	{ "setvar",          control_setvar,            true,  "set a tunable variable",               "<name> <value>"},	{ "listvars",        control_listvars,          true,  "list tunable variables"},	{ "statistics",      control_statistics,        false, "show statistics" },	{ "statisticsreset", control_statistics_reset,  true,  "reset statistics"},	{ "ip",              control_ip,                true,  "show which public ip's that ctdb manages" },	{ "process-exists",  control_process_exists,    true,  "check if a process exists on a node",  "<pid>"},	{ "getdbmap",        control_getdbmap,          true,  "show the database map" },	{ "catdb",           control_catdb,             true,  "dump a database" ,                     "<dbname>"},	{ "getmonmode",      control_getmonmode,        true,  "show monitoring mode" },	{ "setmonmode",      control_setmonmode,        true,  "set monitoring mode", "<0|1>" },	{ "setdebug",        control_setdebug,          true,  "set debug level",                      "<debuglevel>" },	{ "getdebug",        control_getdebug,          true,  "get debug level" },	{ "attach",          control_attach,            true,  "attach to a database",                 "<dbname>" },	{ "dumpmemory",      control_dumpmemory,        true,  "dump memory map to logs" },	{ "getpid",          control_getpid,            true,  "get ctdbd process ID" },	{ "disable",         control_disable,           true,  "disable a nodes public IP" },	{ "enable",          control_enable,            true,  "enable a nodes public IP" },	{ "ban",             control_ban,               true,  "ban a node from the cluster",          "<bantime|0>"},	{ "unban",           control_unban,             true,  "unban a node from the cluster" },	{ "shutdown",        control_shutdown,          true,  "shutdown ctdbd" },	{ "recover",         control_recover,           true,  "force recovery" },	{ "freeze",          control_freeze,            true,  "freeze all databases" },	{ "thaw",            control_thaw,              true,  "thaw all databases" },	{ "killtcp",         kill_tcp,                  false, "kill a tcp connection. Try <num> times.", "<srcip:port> <dstip:port> <num>" },	{ "tickle",          tickle_tcp,                false, "send a tcp tickle ack", "<srcip:port> <dstip:port>" },};/*  show usage message */static void usage(void){	int i;	printf("Usage: ctdb [options] <control>\n" \"Options:\n" \"   -n <node>          choose node number, or 'all' (defaults to local node)\n""   -Y                 generate machinereadable output\n""   -t <timelimit>     set timelimit for control in seconds (default %u)\n", options.timelimit);	printf("Controls:\n");	for (i=0;i<ARRAY_SIZE(ctdb_commands);i++) {		printf("  %-15s %-27s  %s\n", 		       ctdb_commands[i].name, 		       ctdb_commands[i].args?ctdb_commands[i].args:"",		       ctdb_commands[i].msg);	}	exit(1);}/*  main program*/int main(int argc, const char *argv[]){	struct ctdb_context *ctdb;	char *nodestring = NULL;	struct poptOption popt_options[] = {		POPT_AUTOHELP		POPT_CTDB_CMDLINE		{ "timelimit", 't', POPT_ARG_INT, &options.timelimit, 0, "timelimit", "integer" },		{ "node",      'n', POPT_ARG_STRING, &nodestring, 0, "node", "integer|all" },		{ "machinereadable", 'Y', POPT_ARG_NONE, &options.machinereadable, 0, "enable machinereadable output", NULL },		POPT_TABLEEND	};	int opt;	const char **extra_argv;	int extra_argc = 0;	int ret=-1, i;	poptContext pc;	struct event_context *ev;	const char *control;	/* set some defaults */	options.timelimit = 3;	options.vnn = CTDB_CURRENT_NODE;	pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);	while ((opt = poptGetNextOpt(pc)) != -1) {		switch (opt) {		default:			fprintf(stderr, "Invalid option %s: %s\n", 				poptBadOption(pc, 0), poptStrerror(opt));			exit(1);		}	}	/* setup the remaining options for the main program to use */	extra_argv = poptGetArgs(pc);	if (extra_argv) {		extra_argv++;		while (extra_argv[extra_argc]) extra_argc++;	}	if (extra_argc < 1) {		usage();	}	/* setup the node number to contact */	if (nodestring != NULL) {		if (strcmp(nodestring, "all") == 0) {			options.vnn = CTDB_BROADCAST_ALL;		} else {			options.vnn = strtoul(nodestring, NULL, 0);		}	}	control = extra_argv[0];	ev = event_context_init(NULL);	/* initialise ctdb */	ctdb = ctdb_cmdline_client(ev);	if (ctdb == NULL) {		printf("Failed to init ctdb\n");		exit(1);	}	for (i=0;i<ARRAY_SIZE(ctdb_commands);i++) {		if (strcmp(control, ctdb_commands[i].name) == 0) {			int j;			if (options.vnn == CTDB_CURRENT_NODE) {				options.vnn = ctdb_ctrl_getvnn(ctdb, TIMELIMIT(), options.vnn);					}			if (ctdb_commands[i].auto_all && 			    options.vnn == CTDB_BROADCAST_ALL) {				uint32_t *nodes;				uint32_t num_nodes;				ret = 0;				nodes = ctdb_get_connected_nodes(ctdb, TIMELIMIT(), ctdb, &num_nodes);				CTDB_NO_MEMORY(ctdb, nodes);					for (j=0;j<num_nodes;j++) {					options.vnn = nodes[j];					ret |= ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1);				}				talloc_free(nodes);			} else {				ret = ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1);			}			break;		}	}	if (i == ARRAY_SIZE(ctdb_commands)) {		printf("Unknown control '%s'\n", control);		exit(1);	}	return ret;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -