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.

53 lines
1.4 KiB

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