diff options
author | unknown <magnus@neptunus.(none)> | 2004-04-14 12:11:51 +0200 |
---|---|---|
committer | unknown <magnus@neptunus.(none)> | 2004-04-14 12:11:51 +0200 |
commit | f4adc50ea0044f4e330ffbaa712ca38c0fd74ce7 (patch) | |
tree | 886c6b8fcd5699e03622f538ce106ce73b7735b3 /ndb/home | |
parent | e6240e593dca52bb710999ce752b9e6e7feee82c (diff) | |
download | mariadb-git-f4adc50ea0044f4e330ffbaa712ca38c0fd74ce7.tar.gz |
Add more files for NDB Cluster
Diffstat (limited to 'ndb/home')
-rwxr-xr-x | ndb/home/bin/setup-test.sh | 272 | ||||
-rw-r--r-- | ndb/home/lib/funcs.sh | 294 |
2 files changed, 566 insertions, 0 deletions
diff --git a/ndb/home/bin/setup-test.sh b/ndb/home/bin/setup-test.sh new file mode 100755 index 00000000000..61097c30027 --- /dev/null +++ b/ndb/home/bin/setup-test.sh @@ -0,0 +1,272 @@ +#!/bin/sh + +# NAME +# run-test.sh - Run a test program +# +# SYNOPSIS +# setup-test.sh [ -n <ndb dir>] [ -r <run dir>] +# +# DESCRIPTION +# run a test +# +# OPTIONS +# +# EXAMPLES +# +# ENVIRONMENT +# NDB_PROJ_HOME Home dir for ndb +# +# FILES +# $NDB_PROJ_HOME/lib/funcs.sh shell script functions +# +# DIAGNOSTICTS +# +# VERSION +# 1.01 +# +# AUTHOR +# Jonas Oreland +# +# + +progname=`basename $0` +synopsis="setup-test.sh [-x xterm] [ -n <ndb dir>] [ -r <run dir>]" + +: ${NDB_PROJ_HOME:?} # If undefined, exit with error message + +: ${RUN_NDB_NODE_OPTIONS:=--} # If undef, set to --. Keeps getopts happy. + # You may have to experiment a bit + # to get quoting right (if you need it). + + +. $NDB_PROJ_HOME/lib/funcs.sh # Load some good stuff + +# defaults for options related variables +# + +verbose=yes +options="" +ndb_dir=$NDB_TOP +if [ -z "$ndb_dir" ] +then + ndb_dir=`pwd` +fi + +local_dir=`pwd` +own_host=`hostname` +uniq_id=$$.$$ + +_xterm=$XTERM +_rlogin="ssh -X" + +# used if error when parsing the options environment variable +# +env_opterr="options environment variable: <<$options>>" + + +# Option parsing, for the options variable as well as the command line. +# +# We want to be able to set options in an environment variable, +# as well as on the command line. In order not to have to repeat +# the same getopts information twice, we loop two times over the +# getopts while loop. The first time, we process options from +# the options environment variable, the second time we process +# options from the command line. +# +# The things to change are the actual options and what they do. +# +# +for optstring in "$options" "" # 1. options variable 2. cmd line +do + while getopts n:r:x: i $optstring # optstring empty => no arg => cmd line + do + case $i in + + n) ndb_dir=$OPTARG;; # Ndb dir + r) run_dir=$OPTARG;; # Run dir + x) _xterm=$OPTARG;; + \?) syndie $env_opterr;; # print synopsis and exit + + esac + done + + [ -n "$optstring" ] && OPTIND=1 # Reset for round 2, cmdline options + + env_opterr= # Round 2 should not use the value + +done +shift `expr $OPTIND - 1` + +# --- option parsing done --- + +ndb_dir=`abspath $ndb_dir` +run_dir=`abspath $run_dir` + +trace "Verifying arguments" + +if [ ! -d $ndb_dir/bin ] || [ ! -d $ndb_dir/lib ] +then + msg "Ndb home path seems incorrect either $ndb_dir/bin or $ndb_dir/lib not found" + exit 1004 +fi + +ndb_bin=$ndb_dir/bin/ndb +mgm_bin=$ndb_dir/bin/mgmtsrvr +api_lib=$ndb_dir/lib/libNDB_API.so + +if [ ! -x $ndb_bin ] +then + msg "Ndb path seems incorrect ndb binary not found: $ndb_bin" + exit 1004 +fi + +if [ ! -x $mgm_bin ] +then + msg "Ndb path seems incorrect management server binary not found: $mgm_bin" + exit 1004 +fi + +init_config=$run_dir/mgm.1/initconfig.txt +local_config=$run_dir/mgm.1/localcfg.txt +if [ ! -r $init_config ] || [ ! -r $local_config ] +then + msg "Run path seems incorrect $init_config or $local_config not found" + exit 1004 +fi + +trace "Parsing $init_config" +awk -f $NDB_PROJ_HOME/bin/parseConfigFile.awk $init_config > /tmp/run-test.$uniq_id +. /tmp/run-test.$uniq_id +cat /tmp/run-test.$uniq_id +rm -f /tmp/run-test.$uniq_id + +trace "Parsing $local_config" +MgmPort=`grep -v "OwnProcessId" $local_config | cut -d " " -f 2` + +trace "Verifying that mgm port is empty" +telnet $mgm_1 $MgmPort > /tmp/mgm_port.$uniq_id 2>&1 <<EOF +EOF + +if [ 0 -lt `grep -c -i connected /tmp/mgm_port.$uniq_id` ] +then + rm /tmp/mgm_port.$uniq_id + msg "There is already something using port $mgm_1:$MgmPort" + exit 1003 +fi +rm /tmp/mgm_port.$uniq_id + +fixhost(){ + if [ "$1" != localhost ] + then + echo $1 + else + uname -n + fi +} + +do_xterm(){ + title=$1 + shift + xterm -fg black -title "$title" -e $* +} + +save_profile(){ + cp $HOME/.profile /tmp/.profile.$uniq_id +} + +wait_restore_profile(){ + while [ -r /tmp/.profile.$uniq_id ] + do + sleep 1 + done +} + +start_mgm(){ + trace "Starting Management server on: $mgm_1" + save_profile + mgm_1=`fixhost $mgm_1` + + ( + echo "PATH=$ndb_dir/bin:\$PATH" + echo "LD_LIBRARY_PATH=$ndb_dir/lib:\$LD_LIBRARY_PATH" + echo "export PATH LD_LIBRARY_PATH" + echo "cd $run_dir/mgm.1" + echo "ulimit -Sc unlimited" + echo "mv /tmp/.profile.$uniq_id $HOME/.profile" + ) >> $HOME/.profile + do_xterm "Mmg on $mgm_1" ${_rlogin} $mgm_1 & + wait_restore_profile +} + +start_ndb_node(){ + node_id=$1 + dir=$run_dir/ndb.$1 + ndb_host=`eval echo "\$"ndb_$node_id` + ndb_host=`fixhost $ndb_host` + ndb_fs=`eval echo "\$"ndbfs_$node_id` + + trace "Starting Ndb node $node_id on $ndb_host" + save_profile + + ( + echo "PATH=$ndb_dir/bin:\$PATH" + echo "LD_LIBRARY_PATH=$ndb_dir/lib:\$LD_LIBRARY_PATH" + echo "mkdir -p $ndb_fs" + echo "export PATH LD_LIBRARY_PATH" + echo "cd $dir" + echo "ulimit -Sc unlimited" + echo "mv /tmp/.profile.$uniq_id $HOME/.profile" + ) >> $HOME/.profile + do_xterm "Ndb: $node_id on $ndb_host" ${_rlogin} $ndb_host & + wait_restore_profile +} + +start_api_node(){ + node_id=$1 + dir=$run_dir/api.$1 + api_host=`eval echo "\$"api_$node_id` + api_host=`fixhost $api_host` + + trace "Starting api node $node_id on $api_host" + save_profile + + ( + echo "PATH=$ndb_dir/bin:\$PATH" + echo "LD_LIBRARY_PATH=$ndb_dir/lib:\$LD_LIBRARY_PATH" + echo "export PATH LD_LIBRARY_PATH NDB_PROJ_HOME" + echo "cd $dir" + echo "ulimit -Sc unlimited" + echo "mv /tmp/.profile.$uniq_id $HOME/.profile" + ) >> $HOME/.profile + do_xterm "API: $node_id on $api_host" ${_rlogin} $api_host & + wait_restore_profile +} + +for_each_ndb_node(){ + i=1 + j=`expr $mgm_nodes + 1` + while [ $i -le $ndb_nodes ] + do + $* $j + j=`expr $j + 1` + i=`expr $i + 1` + done +} + +for_each_api_node(){ + i=1 + j=`expr $mgm_nodes + $ndb_nodes + 1` + while [ $i -le $api_nodes ] + do + $* $j + j=`expr $j + 1` + i=`expr $i + 1` + done +} + +start_mgm +for_each_ndb_node start_ndb_node +for_each_api_node start_api_node + +exit 0 + diff --git a/ndb/home/lib/funcs.sh b/ndb/home/lib/funcs.sh new file mode 100644 index 00000000000..b7d8914035e --- /dev/null +++ b/ndb/home/lib/funcs.sh @@ -0,0 +1,294 @@ +# NAME +# safe, safe_eval, die, rawdie, syndie, msg, errmsg, +# rawmsg, rawerrmsg, trace, errtrace, is_wordmatch +# - functions for safe execution and convenient printing and tracing +# +# abspath - make a path absolute +# +# SYNOPSIS +# . funcs.sh +# +# is_wordmatch requires perl. +# +# DESCRIPTION +# Funcs.sh is a collection of somewhat related functions. +# The main categories and their respective functions are: +# Controlled execution - safe, safe_eval +# Exiting with a message - die, rawdie, syndie +# Printing messages - msg, errmsg, rawmsg, rawerrmsg +# Tracing - trace, errtrace +# Pattern matching - is_wordmatch +# +# +# ENVIRONMENT +# These variables are not exported, but they are still visible +# to, and used by, these functions. +# +# progname basename of $0 +# verbose empty or non-emtpy, used for tracing +# synopsis string describing the syntax of $progname +# +# VERSION +# 2.0 +# +# AUTHOR +# Jonas Mvlsd +# Jonas Oreland - added abspath + + + + + +# Safely executes the given command and exits +# with the given commands exit code if != 0, +# else the return value ("the functions exit +# code") is 0. Eg: safely cd $install_dir +# +safely () +{ + "$@" + safely_code__=$? + [ $safely_code__ -ne 0 ] && + { errmsg "Command failed: $@. Exit code: $safely_code__."; + exit $safely_code__; } + + : # return "exit code" 0 from function +} + + + + +# Safely_eval executes "eval command" and exits +# with the given commands exit code if != 0, +# else the return value (the functions "exit +# code") is 0. +# +# Safely_eval is just like like safely, but safely_eval does +# "eval command" instead of just "command" +# +# Safely_eval even works with pipes etc., but you have to quote +# the special characters. Eg: safely_eval ls \| wc \> tst.txt 2\>\&1 +# +# +safely_eval () +{ + eval "$@" + safely_eval_code__=$? + [ $safely_eval_code__ -ne 0 ] && + { errmsg "Command failed: $@. Exit code: $safely_eval_code__."; + exit $safely_eval_code__; } + + : # return "exit code" 0 from function +} + + + + + + +# +# safe and safe_eval are deprecated, use safely and safely_eval instead +# + +# Safe executes the given command and exits +# with the given commands exit code if != 0, +# else the return value ("the functions exit +# code") is 0. +# +safe () +{ + "$@" + safe_code__=$? + [ $safe_code__ -ne 0 ] && + { errmsg "Command failed: $@. Exit code: $safe_code__."; + exit $safe_code__; } + + : # return "exit code" 0 from function +} + + + + +# Safe_eval executes "eval command" and exits +# with the given commands exit code if != 0, +# else the return value (the functions "exit +# code") is 0. +# +# Safe_eval is just like like safe, but safe_eval does +# "eval command" instead of just "command" +# +# Safe_eval even works with pipes etc., but you have to quote +# the special characters. Eg: safe_eval ls \| wc \> tst.txt 2\>\&1 +# +# +safe_eval () +{ + eval "$@" + safe_eval_code__=$? + [ $safe_eval_code__ -ne 0 ] && + { errmsg "Command failed: $@. Exit code: $safe_eval_code__."; + exit $safe_eval_code__; } + + : # return "exit code" 0 from function +} + + + + + + +# die prints the supplied message to stderr, +# prefixed with the program name, and exits +# with the exit code given by "-e num" or +# 1, if no -e option is present. +# +die () +{ + die_code__=1 + [ "X$1" = X-e ] && { die_code__=$2; shift 2; } + [ "X$1" = X-- ] && shift + errmsg "$@" + exit $die_code__ +} + + + +# rawdie prints the supplied message to stderr. +# It then exits with the exit code given with "-e num" +# or 1, if no -e option is present. +# +rawdie () +{ + rawdie_code__=1 + [ "X$1" = X-e ] && { rawdie_code__=$2; shift 2; } + [ "X$1" = X-- ] && shift + rawerrmsg "$@" + exit $rawdie_code__ +} + + + + +# Syndie prints the supplied message (if present) to stderr, +# prefixed with the program name, on the first line. +# On the second line, it prints $synopsis. +# It then exits with the exit code given with "-e num" +# or 1, if no -e option is present. +# +syndie () +{ + syndie_code__=1 + [ "X$1" = X-e ] && { syndie_code__=$2; shift 2; } + [ "X$1" = X-- ] && shift + [ -n "$*" ] && msg "$*" + rawdie -e $syndie_code__ "Synopsis: $synopsis" +} + + + + +# msg prints the supplied message to stdout, +# prefixed with the program name. +# +msg () +{ + echo "${progname:-<no program name set>}:" "$@" +} + + + +# msg prints the supplied message to stderr, +# prefixed with the program name. +# +errmsg () +{ + echo "${progname:-<no program name set>}:" "$@" >&2 +} + + + +rawmsg () { echo "$*"; } # print the supplied message to stdout +rawerrmsg () { echo "$*" >&2; } # print the supplied message to stderr + + + +# trace prints the supplied message to stdout if verbose is non-null +# +trace () +{ + [ -n "$verbose" ] && msg "$@" +} + + +# errtrace prints the supplied message to stderr if verbose is non-null +# +errtrace () +{ + [ -n "$verbose" ] && msg "$@" >&2 +} + + + +# SYNTAX +# is_wordmatch candidatelist wordlist +# +# DESCRIPTION +# is_wordmatch returns true if any of the words (candidates) +# in candidatelist is present in wordlist, otherwise it +# returns false. +# +# EXAMPLES +# is_wordmatch "tuareg nixdorf low content" "xx yy zz low fgj turn roff sd" +# returns true, since "low" in candidatelist is present in wordlist. +# +# is_wordmatch "tuareg nixdorf low content" "xx yy zz slow fgj turn roff sd" +# returns false, since none of the words in candidatelist occurs in wordlist. +# +# is_wordmatch "tuareg nixdorf low content" "xx yy zz low fgj tuareg roff" +# returns true, since "low" and "tuareg" in candidatelist occurs in wordlist. +# +is_wordmatch () +{ + is_wordmatch_pattern__=`echo $1 | + sed 's/^/\\\\b/; + s/[ ][ ]*/\\\\b|\\\\b/g; + s/$/\\\\b/;'` + shift + echo "$*" | + perl -lne "m/$is_wordmatch_pattern__/ || exit 1" +} + +# +# abspath +# +# Stolen from http://oase-shareware.org/shell/shelltips/script_programmer.html +# +abspath() +{ + __abspath_D=`dirname "$1"` + __abspath_B=`basename "$1"` + echo "`cd \"$__abspath_D\" 2>/dev/null && pwd || echo \"$__abspath_D\"`/$__abspath_B" +} + +# +# +# NdbExit +# +# +NdbExit() +{ + echo "NdbExit: $1" + exit $1 +} + +NdbGetExitCode() +{ + __res__=`echo $* | awk '{if($1=="NdbExit:") print $2;}'` + if [ -n $__res__ ] + then + echo $__res__ + else + echo 255 + fi +} + |