#include <ndb_global.h>#include <ndb_opts.h>#include "MgmtSrvr.hpp"#include "EventLogger.hpp"#include <Config.hpp>#include "InitConfigFileParser.hpp"#include <SocketServer.hpp>#include "Services.hpp"#include <version.h>#include <kernel_types.h>#include <Properties.hpp>#include <NdbOut.hpp>#include <NdbMain.h>#include <NdbDaemon.h>#include <NdbConfig.h>#include <NdbHost.h>#include <ndb_version.h>#include <ConfigRetriever.hpp>#include <mgmapi_config_parameters.h>#include <NdbAutoPtr.hpp>#include <ndb_mgmclient.hpp>#include <readline/readline.h>Include dependency graph for main.cpp:

Go to the source code of this file.
Classes | |
| struct | MgmGlobals |
| Global Variables used in the management server. More... | |
Defines | |
| #define | DEBUG(x) ndbout << x << endl; |
| #define | HAVE_READLINE |
Enumerations | |
| enum | ndb_mgmd_options { OPT_INTERACTIVE = NDB_STD_OPTIONS_LAST, OPT_NO_NODEID_CHECKS, OPT_NO_DAEMON } |
Functions | |
| int | add_history (const char *command) |
| static int | read_and_execute (Ndb_mgmclient *com, const char *prompt, int _try_reconnect) |
| static void | short_usage_sub (void) |
| static void | usage () |
| int | main (int argc, char **argv) |
Variables | |
| const char | progname [] = "mgmtsrvr" |
| static int | opt_daemon |
| static int | opt_non_interactive |
| static int | opt_interactive |
| static const char * | opt_config_filename = 0 |
| static int | opt_mycnf = 0 |
| int | g_no_nodeid_checks = 0 |
| int | g_print_full_config |
| static MgmGlobals * | glob = 0 |
| bool | g_StopServer |
| bool | g_RestartServer |
| EventLogger | g_eventLogger |
| int | global_mgmt_server_check |
| NDB_STD_OPTS_VARS | |
| static struct my_option | my_long_options [] |
| enum ndb_mgmd_options |
Definition at line 140 of file main.cpp.
00140 { 00141 OPT_INTERACTIVE = NDB_STD_OPTIONS_LAST, 00142 OPT_NO_NODEID_CHECKS, 00143 OPT_NO_DAEMON 00144 };
| int add_history | ( | const char * | command | ) |
Definition at line 1172 of file readline.c.
References e, h, H_ENTER, H_GETSIZE, history(), history_length, HistEvent::num, and rl_initialize().
01173 { 01174 HistEvent ev; 01175 01176 if (h == NULL || e == NULL) 01177 rl_initialize(); 01178 01179 (void)history(h, &ev, H_ENTER, line); 01180 if (history(h, &ev, H_GETSIZE) == 0) 01181 history_length = ev.num; 01182 01183 return (!(history_length > 0)); /* return 0 if all is okay */ 01184 }
Here is the call graph for this function:

| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 193 of file main.cpp.
References BaseString::appfmt(), BaseString::c_str(), MgmtSrvr::check_start(), com, count, exit, free, g_eventLogger, g_print_full_config, g_RestartServer, g_StopServer, MgmtSrvr::getOwnNodeId(), MgmtSrvr::getPort(), glob, global_mgmt_server_check, handle_options(), Logger::info(), MgmtSrvr::init(), MgmGlobals::interface_name, load_default_groups, load_defaults(), MgmGlobals::localNodeId, logfile, MgmGlobals::mgmObject, MY_CHECK_ERROR, MY_GIVE_INFO, my_long_options, my_setwd(), MYF, ndb_end(), NDB_INIT, ndb_std_get_one_option(), NDB_VERSION_STRING, NdbConfig_get_path(), NdbConfig_PidFileName(), NdbConfig_StdoutFileName(), NdbDaemon_ErrorText, NdbDaemon_Make(), ndbout(), ndbout_c(), NdbSleep_MilliSleep(), opt_config_filename, opt_connect_str, opt_daemon, opt_debug, opt_endinfo, opt_interactive, opt_mycnf, opt_non_interactive, MgmGlobals::port, read_and_execute(), MgmApiService::setMgm(), SocketServer::setup(), SIGPIPE, BaseString::snprintf(), MgmGlobals::socketServer, MgmtSrvr::start(), start(), SocketServer::startServer(), SocketServer::stopServer(), SocketServer::stopSessions(), SocketServer::tryBind(), and MgmGlobals::use_specific_ip.
00194 { 00195 int mgm_connect_result; 00196 00197 NDB_INIT(argv[0]); 00198 00199 const char *load_default_groups[]= { "mysql_cluster","ndb_mgmd",0 }; 00200 load_defaults("my",load_default_groups,&argc,&argv); 00201 00202 int ho_error; 00203 #ifndef DBUG_OFF 00204 opt_debug= "d:t:O,/tmp/ndb_mgmd.trace"; 00205 #endif 00206 if ((ho_error=handle_options(&argc, &argv, my_long_options, 00207 ndb_std_get_one_option))) 00208 exit(ho_error); 00209 00210 start: 00211 glob= new MgmGlobals; 00212 00218 #if defined NDB_OSE || defined NDB_SOFTOSE 00219 efs_segment_share(); 00220 #endif 00221 00222 global_mgmt_server_check = 1; 00223 00224 if (opt_interactive || 00225 opt_non_interactive || 00226 g_print_full_config) { 00227 opt_daemon= 0; 00228 } 00229 00230 if (opt_mycnf && opt_config_filename) 00231 { 00232 ndbout_c("Both --mycnf and -f is not supported"); 00233 return 0; 00234 } 00235 00236 if (opt_mycnf == 0 && opt_config_filename == 0) 00237 { 00238 struct stat buf; 00239 if (stat("config.ini", &buf) != -1) 00240 opt_config_filename = "config.ini"; 00241 } 00242 00243 glob->socketServer = new SocketServer(); 00244 00245 MgmApiService * mapi = new MgmApiService(); 00246 00247 glob->mgmObject = new MgmtSrvr(glob->socketServer, 00248 opt_config_filename, 00249 opt_connect_str); 00250 00251 if (g_print_full_config) 00252 goto the_end; 00253 00254 if (glob->mgmObject->init()) 00255 goto error_end; 00256 00257 my_setwd(NdbConfig_get_path(0), MYF(0)); 00258 00259 glob->localNodeId= glob->mgmObject->getOwnNodeId(); 00260 if (glob->localNodeId == 0) { 00261 goto error_end; 00262 } 00263 00264 glob->port= glob->mgmObject->getPort(); 00265 00266 if (glob->port == 0) 00267 goto error_end; 00268 00269 glob->interface_name = 0; 00270 glob->use_specific_ip = false; 00271 00272 if(!glob->use_specific_ip){ 00273 int count= 5; // no of retries for tryBind 00274 while(!glob->socketServer->tryBind(glob->port, glob->interface_name)){ 00275 if (--count > 0) { 00276 NdbSleep_MilliSleep(1000); 00277 continue; 00278 } 00279 ndbout_c("Unable to setup port: %s:%d!\n" 00280 "Please check if the port is already used,\n" 00281 "(perhaps a ndb_mgmd is already running),\n" 00282 "and if you are executing on the correct computer", 00283 (glob->interface_name ? glob->interface_name : "*"), glob->port); 00284 goto error_end; 00285 } 00286 free(glob->interface_name); 00287 glob->interface_name = 0; 00288 } 00289 00290 if(!glob->socketServer->setup(mapi, &glob->port, glob->interface_name)) 00291 { 00292 ndbout_c("Unable to setup management port: %d!\n" 00293 "Please check if the port is already used,\n" 00294 "(perhaps a ndb_mgmd is already running),\n" 00295 "and if you are executing on the correct computer", 00296 glob->port); 00297 delete mapi; 00298 goto error_end; 00299 } 00300 00301 if(!glob->mgmObject->check_start()){ 00302 ndbout_c("Unable to check start management server."); 00303 ndbout_c("Probably caused by illegal initial configuration file."); 00304 goto error_end; 00305 } 00306 00307 if (opt_daemon) { 00308 // Become a daemon 00309 char *lockfile= NdbConfig_PidFileName(glob->localNodeId); 00310 char *logfile= NdbConfig_StdoutFileName(glob->localNodeId); 00311 NdbAutoPtr<char> tmp_aptr1(lockfile), tmp_aptr2(logfile); 00312 00313 if (NdbDaemon_Make(lockfile, logfile, 0) == -1) { 00314 ndbout << "Cannot become daemon: " << NdbDaemon_ErrorText << endl; 00315 return 1; 00316 } 00317 } 00318 00319 #ifndef NDB_WIN32 00320 signal(SIGPIPE, SIG_IGN); 00321 #endif 00322 { 00323 BaseString error_string; 00324 if(!glob->mgmObject->start(error_string)){ 00325 ndbout_c("Unable to start management server."); 00326 ndbout_c("Probably caused by illegal initial configuration file."); 00327 ndbout_c(error_string.c_str()); 00328 goto error_end; 00329 } 00330 } 00331 00332 //glob->mgmObject->saveConfig(); 00333 mapi->setMgm(glob->mgmObject); 00334 00335 char msg[256]; 00336 BaseString::snprintf(msg, sizeof(msg), 00337 "NDB Cluster Management Server. %s", NDB_VERSION_STRING); 00338 ndbout_c(msg); 00339 g_eventLogger.info(msg); 00340 00341 BaseString::snprintf(msg, 256, "Id: %d, Command port: %d", 00342 glob->localNodeId, glob->port); 00343 ndbout_c(msg); 00344 g_eventLogger.info(msg); 00345 00346 g_StopServer = false; 00347 g_RestartServer= false; 00348 glob->socketServer->startServer(); 00349 00350 #if ! defined NDB_OSE && ! defined NDB_SOFTOSE 00351 if(opt_interactive) { 00352 BaseString con_str; 00353 if(glob->interface_name) 00354 con_str.appfmt("host=%s:%d", glob->interface_name, glob->port); 00355 else 00356 con_str.appfmt("localhost:%d", glob->port); 00357 Ndb_mgmclient com(con_str.c_str(), 1); 00358 while(g_StopServer != true && read_and_execute(&com, "ndb_mgm> ", 1)); 00359 } else 00360 #endif 00361 { 00362 while(g_StopServer != true) 00363 NdbSleep_MilliSleep(500); 00364 } 00365 00366 if(g_RestartServer) 00367 g_eventLogger.info("Restarting server..."); 00368 else 00369 g_eventLogger.info("Shutting down server..."); 00370 glob->socketServer->stopServer(); 00371 // We disconnect from the ConfigRetreiver mgmd when we delete glob below 00372 glob->socketServer->stopSessions(true); 00373 g_eventLogger.info("Shutdown complete"); 00374 the_end: 00375 delete glob; 00376 if(g_RestartServer) 00377 goto start; 00378 ndb_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); 00379 return 0; 00380 error_end: 00381 delete glob; 00382 ndb_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); 00383 return 1; 00384 }
Here is the call graph for this function:

| static int read_and_execute | ( | Ndb_mgmclient * | com, | |
| const char * | prompt, | |||
| int | _try_reconnect | |||
| ) | [static] |
Definition at line 63 of file main.cpp.
References add_history(), com, Ndb_mgmclient::execute(), free, NULL, readline(), and strdup().
00064 { 00065 static char *line_read = (char *)NULL; 00066 00067 /* If the buffer has already been allocated, return the memory 00068 to the free pool. */ 00069 if (line_read) 00070 { 00071 free (line_read); 00072 line_read = (char *)NULL; 00073 } 00074 #ifdef HAVE_READLINE 00075 /* Get a line from the user. */ 00076 line_read = readline (prompt); 00077 /* If the line has any text in it, save it on the history. */ 00078 if (line_read && *line_read) 00079 add_history (line_read); 00080 #else 00081 static char linebuffer[254]; 00082 fputs(prompt, stdout); 00083 linebuffer[sizeof(linebuffer)-1]=0; 00084 line_read = fgets(linebuffer, sizeof(linebuffer)-1, stdin); 00085 if (line_read == linebuffer) { 00086 char *q=linebuffer; 00087 while (*q > 31) q++; 00088 *q=0; 00089 line_read= strdup(linebuffer); 00090 } 00091 #endif 00092 return com->execute(line_read,_try_reconnect); 00093 }
Here is the call graph for this function:

| static void short_usage_sub | ( | void | ) | [static] |
Definition at line 178 of file main.cpp.
References my_progname.
00179 { 00180 printf("Usage: %s [OPTIONS]\n", my_progname); 00181 }
| static void usage | ( | void | ) | [static] |
Definition at line 182 of file main.cpp.
References my_long_options, my_print_help(), my_print_variables(), ndb_std_print_version(), and short_usage_sub().
00183 { 00184 short_usage_sub(); 00185 ndb_std_print_version(); 00186 my_print_help(my_long_options); 00187 my_print_variables(my_long_options); 00188 }
Here is the call graph for this function:

| int g_no_nodeid_checks = 0 |
Global variables
Definition at line 134 of file main.cpp.
Referenced by main(), and MgmApiSession::~MgmApiSession().
MgmGlobals* glob = 0 [static] |
Definition at line 309 of file ClusterMgr.cpp.
Referenced by ClusterMgr::execAPI_REGCONF(), and main().
struct my_option my_long_options[] [static] |
Initial value:
{
NDB_STD_OPTS("ndb_mgmd"),
{ "config-file", 'f', "Specify cluster configuration file",
(gptr*) &opt_config_filename, (gptr*) &opt_config_filename, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "print-full-config", 'P', "Print full config and exit",
(gptr*) &g_print_full_config, (gptr*) &g_print_full_config, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "daemon", 'd', "Run ndb_mgmd in daemon mode (default)",
(gptr*) &opt_daemon, (gptr*) &opt_daemon, 0,
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 },
{ "interactive", OPT_INTERACTIVE,
"Run interactive. Not supported but provided for testing purposes",
(gptr*) &opt_interactive, (gptr*) &opt_interactive, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "no-nodeid-checks", OPT_NO_NODEID_CHECKS,
"Do not provide any node id checks",
(gptr*) &g_no_nodeid_checks, (gptr*) &g_no_nodeid_checks, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "nodaemon", OPT_NO_DAEMON,
"Don't run as daemon, but don't read from stdin",
(gptr*) &opt_non_interactive, (gptr*) &opt_non_interactive, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ "mycnf", 256,
"Read cluster config from my.cnf",
(gptr*) &opt_mycnf, (gptr*) &opt_mycnf, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}
const char* opt_config_filename = 0 [static] |
int opt_daemon [static] |
int opt_interactive [static] |
int opt_non_interactive [static] |
1.4.7

