coreos-home-server/service/mariadb
renovate[bot] 6d751566b7 chore(deps): update docker.io/mariadb:10.11 docker digest to 2729275 2024-05-07 00:25:49 +00:00
..
quadlet Enable Podman auto-updates for Redis and MariaDB 2023-10-29 13:31:27 +00:00
systemd mariadb: Move to Quadlet 2023-08-12 11:49:30 +01:00
Containerfile chore(deps): update docker.io/mariadb:10.11 docker digest to 2729275 2024-05-07 00:25:49 +00:00
README.md coturn: Add basic README documentation 2024-02-09 22:52:55 +00:00
mariadb.env.template Flatten directory structures 2022-01-15 11:43:33 +00:00
spec.bu mariadb: Move to Quadlet 2023-08-12 11:49:30 +01:00

README.md

MariaDB

This directory contains a simple systemd service for running an instance of MariaDB.

Deployment

Including the spec.bu file here in your host configuration is enough to have MariaDB enabled on the system -- no other configuration is needed. The following commands will manage the service accordingly:

  • Starting MariaDB: sudo systemctl start mariadb
  • Stopping MariaDB: sudo systemctl stop mariadb
  • Getting logs for the running service: journalctl -feu mariadb

By default, MariaDB listens on the internal network under the mariadb hostname, port 3306. Any services that wish to connect to MariaDB for that hostname and port need to also be included in the internal network.

The systemd service for MariaDB tries to delay readiness checks for until the listener is correctly set up, and will run periodic health-checks to ensure the same.

Use

Depending on MariaDB from other systemd services is as simple as declaring an ordered dependency in the systemd service file, for example:

[Unit]
Description=Service That Uses MariaDB
Wants=[email protected] mariadb.service
After=[email protected] mariadb.service

MariaDB will then be guaranteed to be running before the example service is.

Database Migrations

Services can define an initial state for databases used internally by way of special mariadb-migrate.sql files, which are used by the included mariadb-migrate@ service.

For example, given a service example (in its own directory), we would need a file example/service/mariadb-migrate.sql, containing SQL calls for creating databases, users:

-- Create default database.
CREATE DATABASE IF NOT EXISTS `${EXAMPLE_DATABASE_NAME}`;

-- Create default user with pre-defined password.
CREATE USER IF NOT EXISTS '${EXAMPLE_DATABASE_USERNAME}'@'%' IDENTIFIED BY '${EXAMPLE_DATABASE_PASSWORD}';
GRANT ALL PRIVILEGES ON `${EXAMPLE_DATABASE_NAME}`.* TO '${EXAMPLE_DATABASE_USERNAME}'@'%';

As evidenced above, this file can also have environment variables defined, which are derived from the service-specific example/example.env.template file (if any exists). Running these migrations is as simple a matter as running the aforementioned service, e.g.:

sudo systemctl start mariadb-migrate@example

The systemd journal should provide evidence of execution and reference to any issues that may have occured.