Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for mariadb server config parameter #3763

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions mariadb/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.7.2

- Add option to configure MariaDB server parameters (see also https://github.com/home-assistant/addons/issues/3754)
danielszilagyi marked this conversation as resolved.
Show resolved Hide resolved

## 2.7.1

**Note:** Restart the add-on before upgrade if the current version is lower
Expand Down
5 changes: 5 additions & 0 deletions mariadb/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ If omitted, grants `ALL PRIVILEGES` to the user. Restricting privileges of the u
that Home Assistant uses is not recommended but if you want to allow other applications
to view recorder data should create a user limited to read-only access on the database.

### Option: `parameters.innodb_buffer_pool_size` (optional)

During Home Assistant schema updates some people experienced [errors][migration-issues] on large databases. Increasing this value can help if there is RAM available.

## Home Assistant Configuration

MariaDB will be used by the `recorder` and `history` components within Home Assistant. For more information about setting this up, see the [recorder integration][mariadb-ha-recorder] documentation for Home Assistant.
Expand Down Expand Up @@ -101,6 +105,7 @@ In case you've found a bug, please [open an issue on our GitHub][issue].
[username]: https://mariadb.com/kb/en/create-user/#user-name-component
[hostname]: https://mariadb.com/kb/en/create-user/#host-name-component
[grant]: https://mariadb.com/kb/en/grant/
[migration-issues]: https://github.com/home-assistant/core/issues/125339
[mariadb-ha-recorder]: https://www.home-assistant.io/integrations/recorder/
[discord]: https://discord.gg/c5DvZ4e
[forum]: https://community.home-assistant.io
Expand Down
6 changes: 5 additions & 1 deletion mariadb/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
version: 2.7.1
version: 2.7.2
slug: mariadb
name: MariaDB
description: A SQL database server
Expand All @@ -23,6 +23,8 @@ options:
rights:
- database: homeassistant
username: homeassistant
parameters:
- innodb_buffer_pool_size: 128M
ports:
3306/tcp: null
schema:
Expand All @@ -38,6 +40,8 @@ schema:
CREATE VIEW|DELETE|DELETE HISTORY|DROP|EVENT|GRANT OPTION|INDEX|\
INSERT|LOCK TABLES|SELECT|SHOW VIEW|TRIGGER|UPDATE)?"
username: str
parameters:
- innodb_buffer_pool_size: str
services:
- mysql:provide
startup: system
Expand Down
16 changes: 14 additions & 2 deletions mariadb/rootfs/etc/s6-overlay/s6-rc.d/mariadb-core/run
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@
# Start MariaDB service
# ==============================================================================

# Initialize an empty string to hold the concatenated parameters
param_string=""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be an array? I wonder if your approach of simply concatenating parameters would work with an argument which contains spaces.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have any more parameters in mind that should be adjustable as this was seemingly the one that caused the migration issues.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion to the required format is done in line 15


# Fetch the full array of parameters
item=$(bashio::config "parameters")

while read -r param; do
param_string+="--$param "
done < <(jq --raw-output 'to_entries[] | "\(.key)=\(.value)"' <<< "$item")

param_string=$(echo -n "$param_string" | sed 's/[[:space:]]*$//'|tr -d '\n')

# Start mariadb
bashio::log.info "Starting MariaDB"
bashio::log.info "Starting MariaDB with command line parameters: ${param_string}"
mkdir -p /run/mysqld
exec mysqld --datadir="${MARIADB_DATA}" --user=root < /dev/null
exec mysqld --datadir="${MARIADB_DATA}" --user=root "$param_string" < /dev/null