MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
restart.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB, 2009 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 
20 #include <ndb_global.h>
21 
22 #include <NdbMain.h>
23 #include <OutputStream.hpp>
24 #include <NdbOut.hpp>
25 #include <NdbSleep.h>
26 #include <getarg.h>
27 
28 #include <NdbRestarter.hpp>
29 #include <NDBT.hpp>
30 
31 int main(int argc, const char** argv){
32  ndb_init();
33 
34  const char* _hostName = NULL;
35  int _initial = 0;
36  int _help = 0;
37  int _wait = 1;
38 
39 
40  struct getargs args[] = {
41  { "initial", 'i', arg_flag, &_initial, "Do initial restart", ""},
42  { "wait", '\0', arg_negative_flag, &_wait, "Wait until restarted(default=true)", ""},
43  { "usage", '?', arg_flag, &_help, "Print help", "" }
44 
45  };
46  int num_args = sizeof(args) / sizeof(args[0]);
47  int optind = 0;
48  char desc[] =
49  "hostname:port\n"\
50  "This program will connect to the mgmsrv of a NDB cluster\n"\
51  " and restart the cluster. \n";
52 
53  if(getarg(args, num_args, argc, argv, &optind) || _help) {
54  arg_printusage(args, num_args, argv[0], desc);
55  return NDBT_ProgramExit(NDBT_WRONGARGS);
56  }
57  _hostName = argv[optind];
58 
59  NdbRestarter restarter(_hostName);
60  setOutputLevel(1); // Show only g_err
61  int result = NDBT_OK;
62  if (_initial){
63  ndbout << "Restarting cluster with initial restart" << endl;
64  if (restarter.restartAll(true, false, false) != 0)
65  result = NDBT_FAILED;
66  } else {
67  ndbout << "Restarting cluster " << endl;
68  if (restarter.restartAll() != 0)
69  result = NDBT_FAILED;
70  }
71  if (result == NDBT_FAILED){
72  g_err << "Failed to restart cluster" << endl;
73  return NDBT_ProgramExit(NDBT_FAILED);
74  }
75 
76  if (_wait == 1){
77  ndbout << "Waiting for cluster to start" << endl;
78  if ( restarter.waitClusterStarted(120) != 0){
79  ndbout << "Failed waiting for restart of cluster" << endl;
80  result = NDBT_FAILED;
81  }
82  }
83  ndbout << "Cluster restarted" << endl;
84 
85  return NDBT_ProgramExit(result);
86 }