Update NFS client/server modules for systemd

This commit is contained in:
Eelco Dolstra 2012-10-24 18:10:58 +02:00
parent c6abc572e8
commit b6f9e05269
5 changed files with 61 additions and 60 deletions

View file

@ -80,44 +80,44 @@ in
boot.kernelModules = [ "nfsd" ]; boot.kernelModules = [ "nfsd" ];
jobs.nfsd = boot.systemd.services.nfsd =
{ description = "Kernel NFS server"; { 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 ]; path = [ pkgs.nfsUtils ];
preStart = script =
'' ''
ensure rpcbind
ensure mountd
# Create a state directory required by NFSv4. # Create a state directory required by NFSv4.
mkdir -p /var/lib/nfs/v4recovery mkdir -p /var/lib/nfs/v4recovery
rpc.nfsd \ rpc.nfsd \
${if cfg.hostName != null then "-H ${cfg.hostName}" else ""} \ ${if cfg.hostName != null then "-H ${cfg.hostName}" else ""} \
${builtins.toString cfg.nproc} ${builtins.toString cfg.nproc}
sm-notify -d
''; '';
postStop = "rpc.nfsd 0"; postStop = "rpc.nfsd 0";
postStart = serviceConfig.Type = "oneshot";
'' serviceConfig.RemainAfterExit = true;
ensure statd
ensure idmapd
'';
}; };
jobs.mountd = boot.systemd.services.mountd =
{ description = "Kernel NFS server - mount daemon"; { description = "NFSv3 Mount Daemon";
requires = [ "rpcbind.service" ];
after = [ "rpcbind.service" ];
path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ]; path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ];
preStart = preStart =
'' ''
ensure rpcbind
mkdir -p /var/lib/nfs mkdir -p /var/lib/nfs
touch /var/lib/nfs/rmtab 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 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";
}; };
}; };

View file

@ -59,20 +59,22 @@ in
config = mkIf config.services.rpcbind.enable { config = mkIf config.services.rpcbind.enable {
environment.systemPackages = [ pkgs.rpcbind ];
environment.etc = [ netconfigFile ]; environment.etc = [ netconfigFile ];
jobs.rpcbind = boot.systemd.services.rpcbind =
{ description = "ONC RPC rpcbind"; { description = "ONC RPC Directory Service";
startOn = "started network-interfaces"; wantedBy = [ "multi-user.target" ];
stopOn = "";
daemonType = "fork"; requires = [ "basic.target" ];
after = [ "basic.target" ];
exec = unitConfig.DefaultDependencies = false; # don't stop during shutdown
''
${pkgs.rpcbind}/bin/rpcbind serviceConfig.Type = "forking";
''; serviceConfig.ExecStart = "@${pkgs.rpcbind}/bin/rpcbind rpcbind";
}; };
}; };

View file

@ -40,43 +40,42 @@ in
boot.initrd.kernelModules = mkIf inInitrd [ "nfs" ]; boot.initrd.kernelModules = mkIf inInitrd [ "nfs" ];
# Ensure that statd and idmapd are started before mountall. boot.systemd.services.statd =
jobs.mountall.preStart = { description = "NFSv3 Network Status Monitor";
''
ensure statd || true
ensure idmapd || true
'';
jobs.statd =
{ description = "Kernel NFS server - Network Status Monitor";
path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ]; 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 = preStart =
'' ''
ensure rpcbind
mkdir -p ${nfsStateDir}/sm mkdir -p ${nfsStateDir}/sm
mkdir -p ${nfsStateDir}/sm.bak mkdir -p ${nfsStateDir}/sm.bak
sm-notify -d sm-notify -d
''; '';
daemonType = "fork"; serviceConfig.Type = "forking";
serviceConfig.ExecStart = "@${pkgs.nfsUtils}/sbin/rpc.statd rpc.statd --no-notify";
exec = "rpc.statd --no-notify"; serviceConfig.Restart = "always";
}; };
jobs.idmapd = boot.systemd.services.idmapd =
{ description = "NFS ID mapping daemon"; { 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 = preStart =
'' ''
ensure rpcbind
mkdir -p ${rpcMountpoint} mkdir -p ${rpcMountpoint}
mount -t rpc_pipefs rpc_pipefs ${rpcMountpoint} mount -t rpc_pipefs rpc_pipefs ${rpcMountpoint}
''; '';
@ -86,9 +85,9 @@ in
umount ${rpcMountpoint} umount ${rpcMountpoint}
''; '';
daemonType = "fork"; serviceConfig.Type = "forking";
serviceConfig.ExecStart = "@${pkgs.nfsUtils}/sbin/rpc.idmapd rpc.idmapd -c ${idmapdConfFile}";
exec = "rpc.idmapd -v -c ${idmapdConfFile}"; serviceConfig.Restart = "always";
}; };
}; };

View file

@ -8,7 +8,7 @@ let
[ { mountPoint = "/data"; [ { mountPoint = "/data";
device = "server:/data"; device = "server:/data";
fsType = "nfs"; fsType = "nfs";
options = "bootwait,vers=3"; options = "vers=3";
} }
]; ];
}; };
@ -35,19 +35,20 @@ in
testScript = testScript =
'' ''
$server->waitForJob("nfsd"); $server->waitForJob("nfsd");
$server->waitForJob("network.target");
startAll; startAll;
$client1->waitForJob("tty1"); # depends on filesystems $client1->waitForJob("data.mount");
$client1->succeed("echo bla > /data/foo"); $client1->succeed("echo bla > /data/foo");
$server->succeed("test -e /data/foo"); $server->succeed("test -e /data/foo");
$client2->waitForJob("tty1"); # depends on filesystems $client2->waitForJob("data.mount");
$client2->succeed("echo bla > /data/bar"); $client2->succeed("echo bla > /data/bar");
$server->succeed("test -e /data/bar"); $server->succeed("test -e /data/bar");
# Test whether restarting nfsd works correctly. # 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 $client2->succeed("echo bla >> /data/bar"); # will take 90 seconds due to the NFS grace period
# Test whether we can get a lock. # Test whether we can get a lock.
@ -66,7 +67,7 @@ in
$client2->waitForFile("locked"); $client2->waitForFile("locked");
# Test whether locks survive a reboot of the server. # Test whether locks survive a reboot of the server.
$client1->waitForJob("tty1"); # depends on filesystems $client1->waitForJob("data.mount");
$server->shutdown; $server->shutdown;
$server->start; $server->start;
$client1->succeed("touch /data/xyzzy"); $client1->succeed("touch /data/xyzzy");

View file

@ -34,7 +34,6 @@
[ { mountPoint = "/repos"; [ { mountPoint = "/repos";
device = "storage:/repos"; device = "storage:/repos";
fsType = "nfs"; fsType = "nfs";
options = "bootwait";
} }
]; ];