umorpha-boxes/modules/base-mariadb.sh

39 lines
996 B
Bash
Raw Normal View History

2023-12-14 06:04:24 +00:00
#!/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
2023-12-14 07:01:40 +00:00
PrivateTmp=true
2023-12-14 06:04:24 +00:00
ReadWritePaths=-/var/lib/mysql
2023-12-14 06:32:38 +00:00
ExecStart=/usr/bin/mariadb-install-db --basedir=/usr --datadir=/var/lib/mysql
2023-12-14 06:04:24 +00:00
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
}