summaryrefslogtreecommitdiff
path: root/mysql-test/ndb/ndbcluster.sh
blob: 5334604db336d973a3c4529e0a856a776699abdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/sh
# Copyright (C) 2004 MySQL AB
# For a more info consult the file COPYRIGHT distributed with this file

# This scripts starts the table handler ndbcluster

# configurable parameters, make sure to change in mysqlcluterd as well
port_base="22"  # using ports port_base{"00","01", etc}
fsdir=`pwd`
# end configurable parameters

#BASEDIR is always one above mysql-test directory
CWD=`pwd`
cd ..
BASEDIR=`pwd`
cd $CWD

# Are we using a source or a binary distribution?
if [ -d ../sql ] ; then
   SOURCE_DIST=1
   ndbtop=$BASEDIR/ndb
   exec_ndb=$ndbtop/src/kernel/ndbd
   exec_mgmtsrvr=$ndbtop/src/mgmsrv/ndb_mgmd
   exec_waiter=$ndbtop/tools/ndb_waiter
   exec_mgmtclient=$ndbtop/src/mgmclient/ndb_mgm
else
   BINARY_DIST=1
   if test -x "$BASEDIR/libexec/ndbd"
   then
     exec_ndb=$BASEDIR/libexec/ndbd
     exec_mgmtsrvr=$BASEDIR/libexec/ndb_mgmd
   else
     exec_ndb=$BASEDIR/bin/ndbd
     exec_mgmtsrvr=$BASEDIR/bin/ndb_mgmd
   fi
   exec_waiter=$BASEDIR/bin/ndb_waiter
   exec_mgmtclient=$BASEDIR/bin/ndb_mgm
fi

pidfile=ndbcluster.pid
cfgfile=Ndb.cfg
stop_ndb=
initial_ndb=

while test $# -gt 0; do
  case "$1" in
    --stop)
     stop_ndb=1
     ;;
    --initial)
     flags_ndb=$flags_ndb" -i"
     initial_ndb=1
     ;;
    --data-dir=*)
     fsdir=`echo "$1" | sed -e "s;--data-dir=;;"`
     ;;
    --port-base=*)
     port_base=`echo "$1" | sed -e "s;--port-base=;;"`
     ;;
    -- )  shift; break ;;
    --* ) $ECHO "Unrecognized option: $1"; exit 1 ;;
    * ) break ;;
  esac
  shift
done

fs_ndb=$fsdir/ndbcluster
fs_mgm_1=$fs_ndb/1.ndb_mgm
fs_ndb_2=$fs_ndb/2.ndb_db
fs_ndb_3=$fs_ndb/3.ndb_db
fs_name_2=$fs_ndb/node-2-fs
fs_name_3=$fs_ndb/node-3-fs

NDB_HOME=
export NDB_CONNECTSTRING
if [ ! -x $fsdir ]; then
  echo "$fsdir missing"
  exit 1
fi
if [ ! -x $exec_ndb ]; then
  echo "$exec_ndb missing"
  exit 1
fi
if [ ! -x $exec_mgmtsrv ]; then
  echo "$exec_mgmtsrvr missing"
  exit 1
fi

start_default_ndbcluster() {

# do some checks

NDB_CONNECTSTRING=

if [ $initial_ndb ] ; then
  [ -d $fs_ndb ] || mkdir $fs_ndb
  [ -d $fs_mgm_1 ] || mkdir $fs_mgm_1
  [ -d $fs_ndb_2 ] || mkdir $fs_ndb_2
  [ -d $fs_ndb_3 ] || mkdir $fs_ndb_3
  [ -d $fs_name_2 ] || mkdir $fs_name_2
  [ -d $fs_name_3 ] || mkdir $fs_name_3
fi
if [ -d "$fs_ndb" -a -d "$fs_mgm_1" -a -d "$fs_ndb_2" -a -d "$fs_ndb_3" -a -d "$fs_name_2" -a -d "$fs_name_3" ]; then :; else
  echo "$fs_ndb filesystem directory does not exist"
  exit 1
fi

# set som help variables

ndb_host="localhost"
ndb_port=$port_base"00"
NDB_CONNECTSTRING_BASE="host=$ndb_host:$ndb_port;nodeid="


# Start management server as deamon

NDB_ID="1"
NDB_CONNECTSTRING=$NDB_CONNECTSTRING_BASE$NDB_ID

# Edit file system path and ports in config file

if [ $initial_ndb ] ; then
sed \
    -e s,"CHOOSE_HOSTNAME_".*,"$ndb_host",g \
    -e s,"CHOOSE_FILESYSTEM_NODE_2","$fs_name_2",g \
    -e s,"CHOOSE_FILESYSTEM_NODE_3","$fs_name_3",g \
    -e s,"CHOOSE_PORT_BASE",$port_base,g \
    < ndb/ndb_config_2_node.ini \
    > "$fs_mgm_1/config.ini"
fi

if ( cd $fs_mgm_1 ; echo $NDB_CONNECTSTRING > $cfgfile ; $exec_mgmtsrvr -d -c config.ini ) ; then :; else
  echo "Unable to start $exec_mgmtsrvr from `pwd`"
  exit 1
fi

cat `find $fs_ndb -name 'node*.pid'` > $pidfile

# Start database node 

NDB_ID="2"
NDB_CONNECTSTRING=$NDB_CONNECTSTRING_BASE$NDB_ID
( cd $fs_ndb_2 ; echo $NDB_CONNECTSTRING > $cfgfile ; $exec_ndb -d $flags_ndb & )

cat `find $fs_ndb -name 'node*.pid'` > $pidfile

# Start database node 

NDB_ID="3"
NDB_CONNECTSTRING=$NDB_CONNECTSTRING_BASE$NDB_ID
( cd $fs_ndb_3 ; echo $NDB_CONNECTSTRING > $cfgfile ; $exec_ndb -d $flags_ndb & )

cat `find $fs_ndb -name 'node*.pid'` > $pidfile

# Start management client

sleep 10
echo "show" | $exec_mgmtclient $ndb_host $ndb_port

# test if Ndb Cluster starts properly

NDB_ID="11"
NDB_CONNECTSTRING=$NDB_CONNECTSTRING_BASE$NDB_ID
if ( $exec_waiter ) | grep "NDBT_ProgramExit: 0 - OK"; then :; else
  echo "Ndbcluster startup failed"
  exit 1
fi

echo $NDB_CONNECTSTRING > $cfgfile

cat `find $fs_ndb -name 'node*.pid'` > $pidfile
}

stop_default_ndbcluster() {

#if [ ! -f $pidfile ] ; then
#  exit 0
#fi

if [ ! -f $cfgfile ] ; then
  echo "$cfgfile missing"
  exit 1
fi

ndb_host=`cat $cfgfile | sed -e "s,.*host=\(.*\)\:.*,\1,1"`
ndb_port=`cat $cfgfile | sed -e "s,.*host=$ndb_host\:\([0-9]*\).*,\1,1"`

# Start management client

exec_mgmtclient="$exec_mgmtclient --try-reconnect=1 $ndb_host $ndb_port"

echo "$exec_mgmtclient"
echo "all stop" | $exec_mgmtclient

sleep 5

if [ -f $pidfile ] ; then
  kill `cat $pidfile`
  rm $pidfile
fi

}

if [ $stop_ndb ] ; then
  stop_default_ndbcluster
else
  start_default_ndbcluster
fi

exit 0