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