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

#!/bin/bash
function check() {
PREFIX="recipe:mariadb:check"
dpkg -l mariadb-client | grep -q ^ii || return 9
container_running "$CONTAINER" || return 10
cat <<EOF | lxc_exec "$CONTAINER" || return 20
set -Eeuo pipefail
systemctl is-active mariadb.service &>/dev/null
ss -tlnp | grep 0.0.0.0:3306 | grep -q maria
test -f /etc/default/automysqlbackup
grep -q BACKUPDIR=\"/mnt/BACKUP/mariadb\" /etc/default/automysqlbackup
EOF
echo "container <$CONTAINER> approved successfully!"
return 0
}
function build_device_backup() {
PREFIX="recipe:mariadb:backup"
if ! (lxc config device list "$CONTAINER" | grep -q BACKUP); then
local backup_dir="$HOME/LXD/BACKUP/databases-$CONTAINER"
mkdir -p "$backup_dir"
lxc config device add "$CONTAINER" BACKUP disk source=$backup_dir path=mnt/BACKUP
fi
}
function install() {
sudo_required
PREFIX="recipe:mariadb:install"
: $PREFIX
sudo /opt/debian-bash/tools/idem_apt_install mariadb-client
echowarn "initializing ..."
launch_container "$CONTAINER"
build_device_backup
echowarn "executing various commands onto container <$CONTAINER>, please be patient ..."
lxc exec "$CONTAINER" -- bash <<EOF
set -Eeuo pipefail
cloud-init status --wait >/dev/null
. /opt/debian-bash/lib/functions.sh
apt update && apt dist-upgrade -y
/opt/debian-bash/tools/idem_apt_install mariadb-server automysqlbackup
echo "change bind-adress"
/opt/debian-bash/tools/append_or_replace "^bind-address.*$" "bind-address = 0.0.0.0" /etc/mysql/mariadb.conf.d/50-server.cnf
systemctl restart mariadb.service
function systemctl-exists() ([ \$(systemctl list-unit-files "\${1}*" | wc -l) -gt 3 ])
systemctl-exists exim4.service && systemctl stop exim4.service && systemctl disable exim4.service
/opt/debian-bash/tools/append_or_replace "^BACKUPDIR=.*$" "BACKUPDIR=\"/mnt/BACKUP/mariadb\"" /etc/default/automysqlbackup
exit 0
EOF
echo DONE
}
# MAIN
. "$MIAOU_BASEDIR/lib/init.sh"
arg1_required "$@"
readonly CONTAINER="$1"
check || (
install
check
)