wait_for_socket.sh 2.48 KB
Newer Older
1 2 3 4
#!/bin/sh

###########################################################################

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# NOTE: this script returns 0 (success) even in case of failure (except for
# usage-error). This is because this script is executed under
# mysql-test-run[.pl] and it's better to examine particular problem in log
# file, than just having said that the test case has failed.

###########################################################################

basename=`basename "$0"`
dirname=`dirname "$0"`

###########################################################################

. "$dirname/utils.sh"

###########################################################################

if [ $# -ne 7 ]; then
  echo "Usage: wait_for_socket.sh <executable path> <socket path> <username> <password> <db> <timeout> <test id>"
  exit 1
24 25 26 27 28 29 30 31
fi

client_exe="$1"
socket_path="$2"
username="$3"
password="$4"
db="$5"
total_timeout="$6"
32 33 34 35 36 37 38 39 40 41 42 43
test_id="$7"
log_file="$MYSQLTEST_VARDIR/log/$test_id.log"

log_debug "-- $basename: starting --"
log_debug "client_exe: '$client_exe'"
log_debug "socket_path: '$socket_path'"
log_debug "username: '$username'"
log_debug "password: '$password'"
log_debug "db: '$db'"
log_debug "total_timeout: '$total_timeout'"
log_debug "test_id: '$test_id'"
log_debug "log_file: '$log_file'"
44 45 46 47

###########################################################################

if [ -z "$client_exe" ]; then
48 49
  log_error "Invalid path to client executable ($client_exe)."
  quit 0;
50 51 52
fi

if [ ! -x "$client_exe" ]; then
53 54
  log_error "Client by path '$client_exe' is not available."
  quit 0;
55 56 57
fi

if [ -z "$socket_path" ]; then
58 59
  log_error "Invalid socket patch ($socket_path)."
  quit 0
60 61 62 63
fi

###########################################################################

64
client_args="--silent --connect_timeout=1 --socket=$socket_path "
65 66 67 68 69

[ -n "$username" ] && client_args="$client_args --user=$username "
[ -n "$password" ] && client_args="$client_args --password=$password "
[ -n "$db" ] && client_args="$client_args $db"

70 71
log_debug "client_args: '$client_args'"

72 73 74 75 76 77
###########################################################################

cur_attempt=1

while true; do

78 79
  log_debug "cur_attempt: $cur_attempt."

80
  if ( echo 'quit' | "$client_exe" $client_args >/dev/null 2>&1 ); then
81 82
    log_info "Success: server is ready to accept connection on socket."
    quit 0
83 84 85 86 87 88 89 90 91 92
  fi

  [ $cur_attempt -ge $total_timeout ] && break

  sleep 1

  cur_attempt=`expr $cur_attempt + 1`

done

93 94
log_error "Server does not accept connections after $total_timeout seconds."
quit 0