You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

  1. #!/bin/sh
  2. ###########################################################################
  3. if [ $# -ne 6 ]; then
  4. echo "Usage: wait_for_socket.sh <executable path> <socket path> <username> <password> <db> <timeout>"
  5. exit 0
  6. fi
  7. client_exe="$1"
  8. socket_path="$2"
  9. username="$3"
  10. password="$4"
  11. db="$5"
  12. total_timeout="$6"
  13. ###########################################################################
  14. if [ -z "$client_exe" ]; then
  15. echo "Error: invalid path to client executable ($client_exe)."
  16. exit 0;
  17. fi
  18. if [ ! -x "$client_exe" ]; then
  19. echo "Error: client by path '$client_exe' is not available."
  20. exit 0;
  21. fi
  22. if [ -z "$socket_path" ]; then
  23. echo "Error: invalid socket patch."
  24. exit 0
  25. fi
  26. ###########################################################################
  27. client_args="--silent --socket=$socket_path --connect_timeout=1 "
  28. [ -n "$username" ] && client_args="$client_args --user=$username "
  29. [ -n "$password" ] && client_args="$client_args --password=$password "
  30. [ -n "$db" ] && client_args="$client_args $db"
  31. ###########################################################################
  32. cur_attempt=1
  33. while true; do
  34. if ( echo 'quit' | "$client_exe" $client_args >/dev/null 2>&1 ); then
  35. echo "Success: server is ready to accept connection on socket."
  36. exit 0
  37. fi
  38. [ $cur_attempt -ge $total_timeout ] && break
  39. sleep 1
  40. cur_attempt=`expr $cur_attempt + 1`
  41. done
  42. echo "Error: server does not accept connections after $total_timeout seconds."
  43. exit 0