umorpha-boxes/modules/base-mariadb.sh

38 lines
978 B
Bash

#!/hint/bash -euE
# Copyright (C) 2023 Umorpha Systems
# SPDX-License-Identifier: AGPL-3.0-or-later
packages+=(
mariadb
)
post_install+=(20:mariadb:post_install)
mariadb:post_install() {
local arg_mountpoint=$1
install -Dm644 /dev/stdin "$arg_mountpoint/etc/my.cnf.d/umorpha-server.cnf" <<-'EOF'
[mariadb]
skip_networking=1
EOF
install -Dm644 /dev/stdin "$arg_mountpoint/etc/systemd/system/mariadb-init.service" <<-'EOF'
[Unit]
Description=Initialize MariaDB
Before=mariadb.service
ConditionPathExists=!/var/lib/mysql/mysql/user.frm
[Service]
Type=oneshot
User=mysql
Group=mysql
ProtectSystem=strict
ReadWritePaths=-/var/lib/mysql
ExecStart=/usr/bin/mariadb-install-db --basedir=/usr --datadir=/var/lib/mysql
EOF
mkdir -p -- "$arg_mountpoint/etc/systemd/system/mariadb.service.wants"
ln -s "../mariadb-init.service" "$arg_mountpoint/etc/systemd/system/mariadb.service.wants"
systemctl --root="$arg_mountpoint" enable mariadb.service
}