nixos mysql: make start-up more robust (#41010)
1) Change start-type to ```notify``` when running MariaDB so that we don't have to busy-wait for the socket to appear. 2) Do not manually create the directory under /run as we can get systemd to do that for us. This opens up the possibility later for not having to launch as root.
This commit is contained in:
parent
e243993255
commit
5b468ea6b1
|
@ -231,8 +231,10 @@ in
|
||||||
|
|
||||||
environment.systemPackages = [mysql];
|
environment.systemPackages = [mysql];
|
||||||
|
|
||||||
systemd.services.mysql =
|
systemd.services.mysql = let
|
||||||
{ description = "MySQL Server";
|
hasNotify = (cfg.package == pkgs.mariadb);
|
||||||
|
in {
|
||||||
|
description = "MySQL Server";
|
||||||
|
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
@ -256,17 +258,16 @@ in
|
||||||
|
|
||||||
mkdir -m 0755 -p ${cfg.pidDir}
|
mkdir -m 0755 -p ${cfg.pidDir}
|
||||||
chown -R ${cfg.user} ${cfg.pidDir}
|
chown -R ${cfg.user} ${cfg.pidDir}
|
||||||
|
|
||||||
# Make the socket directory
|
|
||||||
mkdir -p /run/mysqld
|
|
||||||
chmod 0755 /run/mysqld
|
|
||||||
chown -R ${cfg.user} /run/mysqld
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
serviceConfig.ExecStart = "${mysql}/bin/mysqld --defaults-extra-file=${myCnf} ${mysqldOptions}";
|
serviceConfig = {
|
||||||
|
Type = if hasNotify then "notify" else "simple";
|
||||||
|
RuntimeDirectory = "mysqld";
|
||||||
|
ExecStart = "${mysql}/bin/mysqld --defaults-extra-file=${myCnf} ${mysqldOptions}";
|
||||||
|
};
|
||||||
|
|
||||||
postStart =
|
postStart = ''
|
||||||
''
|
${lib.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 ]
|
||||||
|
@ -281,6 +282,7 @@ in
|
||||||
count=$((count++))
|
count=$((count++))
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
''}
|
||||||
|
|
||||||
if [ -f /tmp/mysql_init ]
|
if [ -f /tmp/mysql_init ]
|
||||||
then
|
then
|
||||||
|
|
|
@ -19,7 +19,6 @@ import ./make-test.nix ({ pkgs, ...} : {
|
||||||
startAll;
|
startAll;
|
||||||
|
|
||||||
$master->waitForUnit("mysql");
|
$master->waitForUnit("mysql");
|
||||||
$master->sleep(10); # Hopefully this is long enough!!
|
|
||||||
$master->succeed("echo 'use testdb; select * from tests' | mysql -u root -N | grep 4");
|
$master->succeed("echo 'use testdb; select * from tests' | mysql -u root -N | grep 4");
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue