From b6f9e0526995d3d571cb4ee0819fb51a23571019 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 24 Oct 2012 18:10:58 +0200 Subject: [PATCH] Update NFS client/server modules for systemd --- modules/services/network-filesystems/nfsd.nix | 40 ++++++++--------- modules/services/networking/rpcbind.nix | 22 ++++----- modules/tasks/filesystems/nfs.nix | 45 +++++++++---------- tests/nfs.nix | 11 ++--- tests/trac.nix | 3 +- 5 files changed, 61 insertions(+), 60 deletions(-) diff --git a/modules/services/network-filesystems/nfsd.nix b/modules/services/network-filesystems/nfsd.nix index b4dc014d68ed..995e9bba6030 100644 --- a/modules/services/network-filesystems/nfsd.nix +++ b/modules/services/network-filesystems/nfsd.nix @@ -80,44 +80,44 @@ in boot.kernelModules = [ "nfsd" ]; - jobs.nfsd = - { description = "Kernel NFS server"; + boot.systemd.services.nfsd = + { description = "NFS Server"; - startOn = "started networking"; + wantedBy = [ "multi-user.target" ]; + + requires = [ "rpcbind.service" "mountd.service" ]; + after = [ "rpcbind.service" "mountd.service" "statd.service" ]; path = [ pkgs.nfsUtils ]; - preStart = + script = '' - ensure rpcbind - ensure mountd - # Create a state directory required by NFSv4. mkdir -p /var/lib/nfs/v4recovery rpc.nfsd \ ${if cfg.hostName != null then "-H ${cfg.hostName}" else ""} \ ${builtins.toString cfg.nproc} + + sm-notify -d ''; postStop = "rpc.nfsd 0"; - postStart = - '' - ensure statd - ensure idmapd - ''; + serviceConfig.Type = "oneshot"; + serviceConfig.RemainAfterExit = true; }; - jobs.mountd = - { description = "Kernel NFS server - mount daemon"; + boot.systemd.services.mountd = + { description = "NFSv3 Mount Daemon"; + + requires = [ "rpcbind.service" ]; + after = [ "rpcbind.service" ]; path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ]; preStart = '' - ensure rpcbind - mkdir -p /var/lib/nfs touch /var/lib/nfs/rmtab @@ -133,14 +133,14 @@ in '' } - # exports file is ${exports} - # keep this comment so that this job is restarted whenever exports changes! exportfs -ra ''; - daemonType = "fork"; + restartTriggers = [ exports ]; - exec = "rpc.mountd -f /etc/exports"; + serviceConfig.Type = "forking"; + serviceConfig.ExecStart = "@${pkgs.nfsUtils}/sbin/rpc.mountd rpc.mountd -f /etc/exports"; + serviceConfig.Restart = "always"; }; }; diff --git a/modules/services/networking/rpcbind.nix b/modules/services/networking/rpcbind.nix index 5437d221c1e4..8e3e86a515c1 100644 --- a/modules/services/networking/rpcbind.nix +++ b/modules/services/networking/rpcbind.nix @@ -59,20 +59,22 @@ in config = mkIf config.services.rpcbind.enable { - environment.etc = [netconfigFile]; + environment.systemPackages = [ pkgs.rpcbind ]; - jobs.rpcbind = - { description = "ONC RPC rpcbind"; + environment.etc = [ netconfigFile ]; - startOn = "started network-interfaces"; - stopOn = ""; + boot.systemd.services.rpcbind = + { description = "ONC RPC Directory Service"; - daemonType = "fork"; + wantedBy = [ "multi-user.target" ]; - exec = - '' - ${pkgs.rpcbind}/bin/rpcbind - ''; + requires = [ "basic.target" ]; + after = [ "basic.target" ]; + + unitConfig.DefaultDependencies = false; # don't stop during shutdown + + serviceConfig.Type = "forking"; + serviceConfig.ExecStart = "@${pkgs.rpcbind}/bin/rpcbind rpcbind"; }; }; diff --git a/modules/tasks/filesystems/nfs.nix b/modules/tasks/filesystems/nfs.nix index 491d2de8f24e..055733e456a8 100644 --- a/modules/tasks/filesystems/nfs.nix +++ b/modules/tasks/filesystems/nfs.nix @@ -33,50 +33,49 @@ in config = mkIf (any (fs: fs == "nfs" || fs == "nfs4") config.boot.supportedFilesystems) { services.rpcbind.enable = true; - + system.fsPackages = [ pkgs.nfsUtils ]; boot.kernelModules = [ "sunrpc" ]; boot.initrd.kernelModules = mkIf inInitrd [ "nfs" ]; - # Ensure that statd and idmapd are started before mountall. - jobs.mountall.preStart = - '' - ensure statd || true - ensure idmapd || true - ''; - - jobs.statd = - { description = "Kernel NFS server - Network Status Monitor"; + boot.systemd.services.statd = + { description = "NFSv3 Network Status Monitor"; path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ]; - stopOn = ""; # needed during shutdown + wantedBy = [ "remote-fs-pre.target" "multi-user.target" ]; + before = [ "remote-fs-pre.target" ]; + requires = [ "basic.target" "rpcbind.service" ]; + after = [ "basic.target" "rpcbind.service" "network.target" ]; + + unitConfig.DefaultDependencies = false; # don't stop during shutdown preStart = '' - ensure rpcbind mkdir -p ${nfsStateDir}/sm mkdir -p ${nfsStateDir}/sm.bak sm-notify -d ''; - daemonType = "fork"; - - exec = "rpc.statd --no-notify"; + serviceConfig.Type = "forking"; + serviceConfig.ExecStart = "@${pkgs.nfsUtils}/sbin/rpc.statd rpc.statd --no-notify"; + serviceConfig.Restart = "always"; }; - jobs.idmapd = - { description = "NFS ID mapping daemon"; + boot.systemd.services.idmapd = + { description = "NFSv4 ID Mapping Daemon"; - path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ]; + path = [ pkgs.sysvtools pkgs.utillinux ]; - startOn = "started udev"; + wantedBy = [ "remote-fs-pre.target" "multi-user.target" ]; + before = [ "remote-fs-pre.target" ]; + requires = [ "rpcbind.service" ]; + after = [ "rpcbind.service" ]; preStart = '' - ensure rpcbind mkdir -p ${rpcMountpoint} mount -t rpc_pipefs rpc_pipefs ${rpcMountpoint} ''; @@ -86,9 +85,9 @@ in umount ${rpcMountpoint} ''; - daemonType = "fork"; - - exec = "rpc.idmapd -v -c ${idmapdConfFile}"; + serviceConfig.Type = "forking"; + serviceConfig.ExecStart = "@${pkgs.nfsUtils}/sbin/rpc.idmapd rpc.idmapd -c ${idmapdConfFile}"; + serviceConfig.Restart = "always"; }; }; diff --git a/tests/nfs.nix b/tests/nfs.nix index 7c1ff5e92122..d5b6fc0a692d 100644 --- a/tests/nfs.nix +++ b/tests/nfs.nix @@ -8,7 +8,7 @@ let [ { mountPoint = "/data"; device = "server:/data"; fsType = "nfs"; - options = "bootwait,vers=3"; + options = "vers=3"; } ]; }; @@ -35,19 +35,20 @@ in testScript = '' $server->waitForJob("nfsd"); + $server->waitForJob("network.target"); startAll; - $client1->waitForJob("tty1"); # depends on filesystems + $client1->waitForJob("data.mount"); $client1->succeed("echo bla > /data/foo"); $server->succeed("test -e /data/foo"); - $client2->waitForJob("tty1"); # depends on filesystems + $client2->waitForJob("data.mount"); $client2->succeed("echo bla > /data/bar"); $server->succeed("test -e /data/bar"); # Test whether restarting ‘nfsd’ works correctly. - $server->succeed("stop nfsd; start nfsd"); + $server->succeed("systemctl restart nfsd"); $client2->succeed("echo bla >> /data/bar"); # will take 90 seconds due to the NFS grace period # Test whether we can get a lock. @@ -66,7 +67,7 @@ in $client2->waitForFile("locked"); # Test whether locks survive a reboot of the server. - $client1->waitForJob("tty1"); # depends on filesystems + $client1->waitForJob("data.mount"); $server->shutdown; $server->start; $client1->succeed("touch /data/xyzzy"); diff --git a/tests/trac.nix b/tests/trac.nix index 254996c24407..a35058a1992f 100644 --- a/tests/trac.nix +++ b/tests/trac.nix @@ -33,8 +33,7 @@ fileSystems = pkgs.lib.mkOverride 50 [ { mountPoint = "/repos"; device = "storage:/repos"; - fsType = "nfs"; - options = "bootwait"; + fsType = "nfs"; } ];