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.

63 lines
2.1 KiB

9 months ago
9 months ago
2 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
  1. #!/bin/bash
  2. function check() {
  3. PREFIX="recipe:mariadb:check"
  4. dpkg -l mariadb-client | grep -q ^ii || return 9
  5. container_running "$CONTAINER" || return 10
  6. cat <<EOF | lxc_exec "$CONTAINER" || return 20
  7. set -Eeuo pipefail
  8. systemctl is-active mariadb.service &>/dev/null
  9. ss -tlnp | grep 0.0.0.0:3306 | grep -q maria
  10. test -f /etc/default/automysqlbackup
  11. grep -q BACKUPDIR=\"/mnt/BACKUP/mariadb\" /etc/default/automysqlbackup
  12. EOF
  13. }
  14. function build_device_backup() {
  15. PREFIX="recipe:mariadb:backup"
  16. if ! (lxc config device list "$CONTAINER" | grep -q BACKUP); then
  17. local backup_dir="$HOME/LXD/BACKUP/databases-$CONTAINER"
  18. mkdir -p "$backup_dir"
  19. lxc config device add "$CONTAINER" BACKUP disk source=$backup_dir path=mnt/BACKUP
  20. fi
  21. }
  22. function install() {
  23. sudo_required
  24. PREFIX="recipe:mariadb:install"
  25. : $PREFIX
  26. sudo /opt/miaou-bash/tools/idem_apt_install mariadb-client
  27. echowarn "initializing ..."
  28. launch_container "$CONTAINER"
  29. build_device_backup
  30. echowarn "executing various commands inside container <$CONTAINER>, please be patient ..."
  31. lxc exec "$CONTAINER" -- bash <<EOF
  32. set -Eeuo pipefail
  33. cloud-init status --wait >/dev/null
  34. . /opt/miaou-bash/lib/functions.sh
  35. apt update && apt dist-upgrade -y
  36. /opt/miaou-bash/tools/idem_apt_install mariadb-server automysqlbackup
  37. echo "change bind-adress"
  38. /opt/miaou-bash/tools/append_or_replace "^bind-address.*$" "bind-address = 0.0.0.0" /etc/mysql/mariadb.conf.d/50-server.cnf
  39. systemctl restart mariadb.service
  40. function systemctl-exists() ([ \$(systemctl list-unit-files "\${1}*" | wc -l) -gt 3 ])
  41. systemctl-exists exim4.service && systemctl stop exim4.service && systemctl disable exim4.service
  42. /opt/miaou-bash/tools/append_or_replace "^BACKUPDIR=.*$" "BACKUPDIR=\"/mnt/BACKUP/mariadb\"" /etc/default/automysqlbackup
  43. exit 0
  44. EOF
  45. echo DONE
  46. }
  47. # MAIN
  48. . "$MIAOU_BASEDIR/lib/init.sh"
  49. arg1_required "$@"
  50. readonly CONTAINER="$1"
  51. check || (
  52. install
  53. check
  54. )