fork 0k-charms
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.

60 lines
1.9 KiB

  1. #!/bin/bash
  2. ## Init is run on host
  3. ## For now it is run every time the script is launched, but
  4. ## it should be launched only once after build.
  5. ## Accessible variables are:
  6. ## - SERVICE_NAME Name of current service
  7. ## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
  8. ## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
  9. ## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
  10. . lib/common
  11. set -e
  12. if [ "${HOST_DATASTORE+x}" ]; then
  13. export HOST_DB_PASSFILE="$HOST_DATASTORE/${SERVICE_NAME}$DB_DATADIR/my.cnf"
  14. else
  15. export HOST_DB_PASSFILE="$CLIENT_DB_PASSFILE"
  16. fi
  17. if ! [ -d "$HOST_DATASTORE/${SERVICE_NAME}$DB_DATADIR" ]; then
  18. MYSQL_ROOT_PASSWORD="$(gen_password)"
  19. debug docker run -e "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" \
  20. --rm \
  21. -v "$DATA_DIR:$DB_DATADIR" \
  22. --entrypoint /bin/bash "$DOCKER_BASE_IMAGE"
  23. docker run -e "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" \
  24. --rm \
  25. -v "$DATA_DIR:$DB_DATADIR" \
  26. --entrypoint /bin/bash "$DOCKER_BASE_IMAGE" -c '
  27. mysqld() {
  28. echo "diverted mysqld call..." >&2;
  29. echo "$*" | grep -E "(--help|--skip-networking)" >/dev/null 2>&1 || return;
  30. echo " .. Allowing call." >&2;
  31. /usr/sbin/mysqld "$@";
  32. }
  33. export -f mysqld;
  34. /docker-entrypoint.sh mysqld' || true
  35. ## docker errorlevel is still 0 even if it failed.
  36. ## AND we must ignore mysqld error !
  37. [ "$(find "$DATA_DIR" \
  38. -maxdepth 0 -type d -empty 2>/dev/null)" ] && {
  39. err "Docker run probably failed to do it's job."
  40. exit 1
  41. }
  42. ## XXXvlab: this won't help support multiple project running on the
  43. ## same host
  44. cat <<EOF > "$HOST_DB_PASSFILE"
  45. [client]
  46. password=$MYSQL_ROOT_PASSWORD
  47. EOF
  48. chmod 600 "$HOST_DB_PASSFILE"
  49. info "New root password for mysql. "
  50. fi