provisioning tool for building opinionated architecture
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.

55 lines
1.6 KiB

  1. #!/bin/bash
  2. function check() {
  3. PREFIX="recipe:redis:check"
  4. container_running "$CONTAINER" || return 10
  5. echo "checking redis regarding access to its ip address <$REDIS_IP>..."
  6. lxc exec "$CONTAINER" -- bash <<EOF
  7. set -Eeuo pipefail
  8. systemctl is-active redis.service &>/dev/null
  9. ss -tlnp | grep redis | grep -q $REDIS_IP:6379
  10. test -f /etc/redis/redis.conf
  11. grep -Eq "^protected-mode no" /etc/redis/redis.conf
  12. EOF
  13. status="$?"
  14. [[ $status -eq 0 ]] && echo "container <$CONTAINER> approved!"
  15. return $status
  16. }
  17. function install() {
  18. PREFIX="recipe:redis:install"
  19. : "$PREFIX"
  20. credential_redis=$(load_yaml_from_expanded credential.redis)
  21. echowarn "initializing redis regarding access to its IP address <$REDIS_IP>..."
  22. launch_container "$CONTAINER"
  23. lxc exec "$CONTAINER" -- bash <<EOF
  24. set -Eeuo pipefail
  25. . /opt/miaou-bash/lib/functions.sh
  26. /opt/miaou-bash/tools/idem_apt_install redis
  27. /opt/miaou-bash/tools/append_or_replace "^bind .*$" "bind $REDIS_IP" /etc/redis/redis.conf
  28. /opt/miaou-bash/tools/append_or_replace "^protected-mode .*$" "protected-mode no" /etc/redis/redis.conf
  29. /opt/miaou-bash/tools/append_or_replace "^requirepass .*$" "requirepass $credential_redis" /etc/redis/redis.conf
  30. systemctl restart redis.service
  31. EOF
  32. PREFIX="" echo OK
  33. }
  34. # MAIN
  35. . "$MIAOU_BASEDIR/lib/init.sh"
  36. arg1_required "$@"
  37. CONTAINER="$1"
  38. REDIS_IP=$(lxc list "$CONTAINER" -c 4 -f csv | cut -d ' ' -f1)
  39. readonly CONTAINER REDIS_IP
  40. check || (
  41. install
  42. check
  43. )