umorpha-boxes/modules/base-mariadb.sh

39 lines
996 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
PrivateTmp=true
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
}