nixos/mysql: move ExecStartPost into postStart

This commit is contained in:
Aaron Andersen 2020-08-11 22:04:16 -04:00
parent e3c210dfd1
commit f08049e712

View File

@ -375,19 +375,10 @@ in
fi
'';
serviceConfig = {
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";
ExecStartPost =
let
postStart = let
# The super user account to use on *first* run of MySQL server
superUser = if isMariaDB then cfg.user else "root";
setupScript = pkgs.writeScript "mysql-setup" ''
#!${pkgs.runtimeShell} -e
in ''
${optionalString (!hasNotify) ''
# Wait until the MySQL server is available for use
count=0
@ -407,7 +398,7 @@ in
if [ -f ${cfg.dataDir}/mysql_init ]
then
# While MariaDB comes with a 'mysql' super user account since 10.4.x MySQL does not
# While MariaDB comes with a 'mysql' super user account since 10.4.x, MySQL does not
# Since we don't want to run this service as 'root' we need to ensure the account exists on first run
( echo "CREATE USER IF NOT EXISTS '${cfg.user}'@'localhost' IDENTIFIED WITH ${if isMariaDB then "unix_socket" else "auth_socket"};"
echo "GRANT ALL PRIVILEGES ON *.* TO '${cfg.user}'@'localhost' WITH GRANT OPTION;"
@ -485,8 +476,13 @@ in
) | ${cfg.package}/bin/mysql -N
'') cfg.ensureUsers}
'';
in
"${setupScript}";
serviceConfig = {
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;