nixos/mysql: turn ExecStartPost into a shell script and simplify code

This commit is contained in:
Aaron Andersen 2019-06-30 21:58:27 -04:00
parent 76a50f0f85
commit e0590da813

View File

@ -317,11 +317,10 @@ in
RuntimeDirectoryMode = "0755"; RuntimeDirectoryMode = "0755";
# The last two environment variables are used for starting Galera clusters # The last two environment variables are used for starting Galera clusters
ExecStart = "${mysql}/bin/mysqld --defaults-file=/etc/my.cnf ${mysqldOptions} $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION"; ExecStart = "${mysql}/bin/mysqld --defaults-file=/etc/my.cnf ${mysqldOptions} $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION";
}; ExecStartPost =
postStart =
let let
cmdWatchForMysqlSocket = '' setupScript = pkgs.writeShellScript "mysql-setup" ''
${optionalString (!hasNotify) ''
# Wait until the MySQL server is available for use # Wait until the MySQL server is available for use
count=0 count=0
while [ ! -e /run/mysqld/mysqld.sock ] while [ ! -e /run/mysqld/mysqld.sock ]
@ -336,8 +335,11 @@ in
count=$((count++)) count=$((count++))
sleep 1 sleep 1
done done
''; ''}
cmdInitialDatabases = concatMapStrings (database: ''
if [ -f /tmp/mysql_init ]
then
${concatMapStrings (database: ''
# Create initial databases # Create initial databases
if ! test -e "${cfg.dataDir}/${database.name}"; then if ! test -e "${cfg.dataDir}/${database.name}"; then
echo "Creating initial database: ${database.name}" echo "Creating initial database: ${database.name}"
@ -358,13 +360,8 @@ in
''} ''}
) | ${mysql}/bin/mysql -u root -N ) | ${mysql}/bin/mysql -u root -N
fi fi
'') cfg.initialDatabases; '') cfg.initialDatabases}
in
lib.optionalString (!hasNotify) cmdWatchForMysqlSocket + ''
if [ -f /tmp/mysql_init ]
then
${cmdInitialDatabases}
${optionalString (cfg.replication.role == "master") ${optionalString (cfg.replication.role == "master")
'' ''
# Set up the replication master # Set up the replication master
@ -413,8 +410,10 @@ in
'') user.ensurePermissions)} '') user.ensurePermissions)}
) | ${mysql}/bin/mysql -u root -N ) | ${mysql}/bin/mysql -u root -N
'') cfg.ensureUsers} '') cfg.ensureUsers}
'';
''; # */ in
setupScript;
};
}; };
}; };