From 75c67b01946b53c711e775db766f53f334927d63 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 18 Dec 2012 13:40:04 +0100 Subject: mysql: Port to systemd --- modules/services/databases/mysql.nix | 30 ++++++++++++++++-------------- modules/services/databases/postgresql.nix | 4 ++-- 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'modules/services/databases') diff --git a/modules/services/databases/mysql.nix b/modules/services/databases/mysql.nix index 2c35c13255e..ef29d563c72 100644 --- a/modules/services/databases/mysql.nix +++ b/modules/services/databases/mysql.nix @@ -91,6 +91,7 @@ in description = "A file containing SQL statements to be executed on the first startup. Can be used for granting certain permissions on the database"; }; + # FIXME: remove this option; it's a really bad idea. rootPassword = mkOption { default = null; description = "Path to a file containing the root password, modified on the first startup. Not specifying a root password will leave the root password empty."; @@ -140,10 +141,12 @@ in environment.systemPackages = [mysql]; - jobs.mysql = - { description = "MySQL server"; + boot.systemd.services.mysql = + { description = "MySQL Server"; - startOn = "filesystem"; + wantedBy = [ "multi-user.target" ]; + + unitConfig.RequiresMountsFor = "${cfg.dataDir}"; preStart = '' @@ -156,9 +159,12 @@ in mkdir -m 0700 -p ${cfg.pidDir} chown -R ${cfg.user} ${cfg.pidDir} - - ${mysql}/libexec/mysqld --defaults-extra-file=${myCnf} ${mysqldOptions} & + ''; + serviceConfig.ExecStart = "${mysql}/libexec/mysqld --defaults-extra-file=${myCnf} ${mysqldOptions}"; + + postStart = + '' # Wait until the MySQL server is available for use count=0 while [ ! -e /tmp/mysql.sock ] @@ -183,7 +189,7 @@ in echo "Creating initial database: ${database.name}" ( echo "create database ${database.name};" echo "use ${database.name};" - + if [ -f "${database.schema}" ] then cat ${database.schema} @@ -204,7 +210,7 @@ in ${optionalString (cfg.rootPassword != null) '' # Change root password - + ( echo "use mysql;" echo "update user set Password=password('$(cat ${cfg.rootPassword})') where User='root';" echo "flush privileges;" @@ -213,14 +219,10 @@ in rm /tmp/mysql_init fi - ''; - - postStop = "${mysql}/bin/mysqladmin ${optionalString (cfg.rootPassword != null) "--user=root --password=\"$(cat ${cfg.rootPassword})\""} shutdown"; - - # !!! Need a postStart script to wait until mysqld is ready to - # accept connections. + ''; # */ - extraConfig = "kill timeout 60"; + serviceConfig.ExecStop = + "${mysql}/bin/mysqladmin ${optionalString (cfg.rootPassword != null) "--user=root --password=\"$(cat ${cfg.rootPassword})\""} shutdown"; }; }; diff --git a/modules/services/databases/postgresql.nix b/modules/services/databases/postgresql.nix index c34ae9037f2..a013a3ccc3d 100644 --- a/modules/services/databases/postgresql.nix +++ b/modules/services/databases/postgresql.nix @@ -156,10 +156,10 @@ in environment.systemPackages = [postgresql]; boot.systemd.services.postgresql = - { description = "PostgreSQL"; + { description = "PostgreSQL Server"; wantedBy = [ "multi-user.target" ]; - after = [ "network.target" "fs.target" ]; + after = [ "network.target" ]; environment = { TZ = config.time.timeZone; -- cgit 1.4.1