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.

59 lines
1.4 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. set -e
  11. uid=$(docker_get_uid "$SERVICE_NAME" "redis")
  12. CONFIG=$SERVICE_CONFIGSTORE/etc/redis-local.conf
  13. PASSWORD=$(options-get password 2>/dev/null) || {
  14. if [ -e "$CONFIG" ]; then
  15. PASSWORD=$(grep ^requirepass "$CONFIG" | sed -r 's/^requirepass\s+(.+)$/\1/g')
  16. fi
  17. if [ -z "$ADMIN_PASSWORD" ]; then
  18. info "Generating odoo admin password"
  19. PASSWORD=$(gen_password 64)
  20. fi
  21. }
  22. mkdir -p "$(dirname "$CONFIG")"
  23. cat <<EOF > "$CONFIG"
  24. daemonize no
  25. loglevel notice
  26. logfile ""
  27. bind 0.0.0.0
  28. requirepass $PASSWORD
  29. EOF
  30. chown -v "$uid" "$CONFIG"
  31. dirs=(/var/log/redis /var/lib/redis)
  32. host_dirs=()
  33. for dir in "${dirs[@]}"; do
  34. host_dirs+=("$SERVICE_DATASTORE$dir")
  35. done
  36. mkdir -p "${host_dirs[@]}"
  37. find "${host_dirs[@]}" \! -user "$uid" \
  38. -exec chown -v "$uid" {} + || true
  39. config_hash=$(cat "$CONFIG" | md5_compat) || exit 1
  40. init-config-add "
  41. $MASTER_BASE_SERVICE_NAME:
  42. labels:
  43. - compose.config_hash=$config_hash
  44. "