1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-19 16:09:19 +03:00

nixos/mysql: reformat, move logical steps into variables

define commands like "waiting for the mysql socket to appear" or "setup
initial databases" in a let expression, so the main control flow becomes
more readable.
This commit is contained in:
Florian Klink 2019-05-17 00:12:20 +02:00
parent 50dda813e2
commit 25494cc193

View file

@ -318,13 +318,11 @@ in
pkgs.nettools pkgs.nettools
]; ];
preStart = preStart = ''
''
if ! test -e ${cfg.dataDir}/mysql; then if ! test -e ${cfg.dataDir}/mysql; then
${mysql}/bin/mysql_install_db --defaults-file=/etc/my.cnf ${installOptions} ${mysql}/bin/mysql_install_db --defaults-file=/etc/my.cnf ${installOptions}
touch /tmp/mysql_init touch /tmp/mysql_init
fi fi
''; '';
serviceConfig = { serviceConfig = {
@ -336,8 +334,9 @@ in
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";
}; };
postStart = '' postStart =
${lib.optionalString (!hasNotify) '' let
cmdWatchForMysqlSocket = ''
# 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 ]
@ -352,12 +351,8 @@ 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}"
@ -378,8 +373,13 @@ 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