summary refs log tree commit diff
path: root/nixos/modules/services/databases
diff options
context:
space:
mode:
authorAaron Andersen <aaron@fosslib.net>2021-02-17 14:16:26 -0500
committerAaron Andersen <aaron@fosslib.net>2021-02-17 15:50:20 -0500
commit4b9262786d7666b53a087fc345486c64151ce4c2 (patch)
tree4113378811a43086cbf7283f1856bb31aad62005 /nixos/modules/services/databases
parentdc0e2bfd78a0da76d3d49ee9330cf60cbffb66bc (diff)
downloadnixpkgs-4b9262786d7666b53a087fc345486c64151ce4c2.tar
nixpkgs-4b9262786d7666b53a087fc345486c64151ce4c2.tar.gz
nixpkgs-4b9262786d7666b53a087fc345486c64151ce4c2.tar.bz2
nixpkgs-4b9262786d7666b53a087fc345486c64151ce4c2.tar.lz
nixpkgs-4b9262786d7666b53a087fc345486c64151ce4c2.tar.xz
nixpkgs-4b9262786d7666b53a087fc345486c64151ce4c2.tar.zst
nixpkgs-4b9262786d7666b53a087fc345486c64151ce4c2.zip
nixos/mysql: properly configure mariadb for galera recovery
Diffstat (limited to 'nixos/modules/services/databases')
-rw-r--r--nixos/modules/services/databases/mysql.nix15
1 files changed, 13 insertions, 2 deletions
diff --git a/nixos/modules/services/databases/mysql.nix b/nixos/modules/services/databases/mysql.nix
index 7d0a3f9afc4..cf105daeb04 100644
--- a/nixos/modules/services/databases/mysql.nix
+++ b/nixos/modules/services/databases/mysql.nix
@@ -375,6 +375,18 @@ in
           fi
         '';
 
+        script = ''
+          # https://mariadb.com/kb/en/getting-started-with-mariadb-galera-cluster/#systemd-and-galera-recovery
+          if test -n "''${_WSREP_START_POSITION}"; then
+            if test -e "${cfg.package}/bin/galera_recovery"; then
+              VAR=$(cd ${cfg.package}/bin/..; ${cfg.package}/bin/galera_recovery); [[ $? -eq 0 ]] && export _WSREP_START_POSITION=$VAR || exit 1
+            fi
+          fi
+
+          # The last two environment variables are used for starting Galera clusters
+          exec ${cfg.package}/bin/mysqld --defaults-file=/etc/my.cnf ${mysqldOptions} $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION
+        '';
+
         postStart = let
           # The super user account to use on *first* run of MySQL server
           superUser = if isMariaDB then cfg.user else "root";
@@ -481,8 +493,7 @@ in
           Type = if hasNotify then "notify" else "simple";
           Restart = "on-abort";
           RestartSec = "5s";
-          # The last two environment variables are used for starting Galera clusters
-          ExecStart = "${cfg.package}/bin/mysqld --defaults-file=/etc/my.cnf ${mysqldOptions} $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION";
+
           # User and group
           User = cfg.user;
           Group = cfg.group;