summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorPeter Hoeg <peter@hoeg.com>2018-05-24 22:42:16 +0800
committerxeji <36407913+xeji@users.noreply.github.com>2018-05-24 16:42:16 +0200
commit5b468ea6b1d8d243847a05bdf5603e8abdfd7b4e (patch)
tree43f1634f050c75b7f153bac996c5ddf77c2ac862 /nixos
parente24399325535c0b0b7c19ea8e73ff61409d79ff4 (diff)
downloadnixpkgs-5b468ea6b1d8d243847a05bdf5603e8abdfd7b4e.tar
nixpkgs-5b468ea6b1d8d243847a05bdf5603e8abdfd7b4e.tar.gz
nixpkgs-5b468ea6b1d8d243847a05bdf5603e8abdfd7b4e.tar.bz2
nixpkgs-5b468ea6b1d8d243847a05bdf5603e8abdfd7b4e.tar.lz
nixpkgs-5b468ea6b1d8d243847a05bdf5603e8abdfd7b4e.tar.xz
nixpkgs-5b468ea6b1d8d243847a05bdf5603e8abdfd7b4e.tar.zst
nixpkgs-5b468ea6b1d8d243847a05bdf5603e8abdfd7b4e.zip
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.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/databases/mysql.nix22
-rw-r--r--nixos/tests/mysql.nix1
2 files changed, 12 insertions, 11 deletions
diff --git a/nixos/modules/services/databases/mysql.nix b/nixos/modules/services/databases/mysql.nix
index 66c9330c355..15b9c788e87 100644
--- a/nixos/modules/services/databases/mysql.nix
+++ b/nixos/modules/services/databases/mysql.nix
@@ -231,8 +231,10 @@ in
 
     environment.systemPackages = [mysql];
 
-    systemd.services.mysql =
-      { description = "MySQL Server";
+    systemd.services.mysql = let
+      hasNotify = (cfg.package == pkgs.mariadb);
+    in {
+        description = "MySQL Server";
 
         after = [ "network.target" ];
         wantedBy = [ "multi-user.target" ];
@@ -256,17 +258,16 @@ in
 
             mkdir -m 0755 -p ${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
             count=0
             while [ ! -e /run/mysqld/mysqld.sock ]
@@ -281,6 +282,7 @@ in
                 count=$((count++))
                 sleep 1
             done
+          ''}
 
             if [ -f /tmp/mysql_init ]
             then
diff --git a/nixos/tests/mysql.nix b/nixos/tests/mysql.nix
index baaebf9f10d..c18fee6c749 100644
--- a/nixos/tests/mysql.nix
+++ b/nixos/tests/mysql.nix
@@ -19,7 +19,6 @@ import ./make-test.nix ({ pkgs, ...} : {
     startAll;
 
     $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");
   '';
 })