~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/test/tools/restart.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

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