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.

65 lines
2.1 KiB

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