Commit 41ec4243 authored by 6543's avatar 6543
Browse files

services.mysql: wait for galera cluster sync to be done

parent 0ce9de03
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -433,6 +433,25 @@ in
            done
          ''}

          ${lib.optionalString isMariaDB ''
            # If MariaDB is used in an Galera cluster, we have to check if the sync is done,
            # or it will fail to init the database while joining, so we get in an broken non recoverable state
            # so we wait until we have an synced state
            if ${cfg.package}/bin/mysql -u ${superUser} -N -e "SHOW VARIABLES LIKE 'wsrep_on'" 2>/dev/null | ${lib.getExe' pkgs.gnugrep "grep"} -q 'ON'; then
              echo "Galera cluster detected, waiting for node to be synced..."
              while true; do
                STATE=$(${cfg.package}/bin/mysql -u ${superUser} -N -e "SHOW STATUS LIKE 'wsrep_local_state_comment'" | ${lib.getExe' pkgs.gawk "awk"} '{print $2}')
                if [ "$STATE" = "Synced" ]; then
                  echo "Node is synced"
                  break
                else
                  echo "Current state: $STATE - Waiting for 1 second..."
                  sleep 1
                fi
              done
            fi
          ''}

          if [ -f ${cfg.dataDir}/mysql_init ]
          then
              # While MariaDB comes with a 'mysql' super user account since 10.4.x, MySQL does not