Commit 1bb0aa8f authored by Julien Muchembled's avatar Julien Muchembled

ERP5: fix mariadb initialization when datadir is not a simple directory

The previous way to initialize ~/srv/mariadb relied on /bin/mv, so that
it's atomic, making [template-mysqld-wrapper] idempotent (think of a
crash in the middle mysql_install_db). However, mv only works if
~/srv/mariadb is a simple directory: it fails if it's a symlink,
a mount point, or a subvolume (btrfs).

When using extra storage devices for some data, one may prefer to only
put the data (e.g. ~/srv/mariadb) and not the whole slapos partition.
Then if we want a resilient ERP5 with catalog's datadir on a separate
storage device, the importer script must be able to reinitialize
~/srv/mariadb whatever its type.
parent 05f78f2c
...@@ -105,15 +105,17 @@ template = ...@@ -105,15 +105,17 @@ template =
inline:{% raw %}#!/bin/sh -e inline:{% raw %}#!/bin/sh -e
basedir='${mariadb:location}' basedir='${mariadb:location}'
datadir='{{datadir}}' datadir='{{datadir}}'
[ -e "$datadir" ] || { marker=$datadir/.slapos_initializing
rm -vrf "$datadir.new" [ -d "$datadir/mysql" ] && [ ! -f "$marker" ] || {
find "$datadir/" -mindepth 1 ! -path $marker -delete || mkdir "$datadir"
touch "$marker"
"$basedir/scripts/mysql_install_db" \ "$basedir/scripts/mysql_install_db" \
--defaults-file='{{defaults_file}}' \ --defaults-file='{{defaults_file}}' \
--skip-name-resolve \ --skip-name-resolve \
--auth-root-authentication-method=normal \ --auth-root-authentication-method=normal \
--basedir="$basedir" --plugin_dir="$basedir/lib/plugin" \ --basedir="$basedir" --plugin_dir="$basedir/lib/plugin" \
--datadir="$datadir.new" --datadir="$datadir"
mv -v "$datadir.new" "$datadir" rm "$marker"
} }
{%- if environ is defined %} {%- if environ is defined %}
{%- for variable in environ.splitlines() %} {%- for variable in environ.splitlines() %}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment