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" ];
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";
};
};

View file

@ -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";
};
};

View file

@ -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";
};
};

View file

@ -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");

View file

@ -33,8 +33,7 @@
fileSystems = pkgs.lib.mkOverride 50
[ { mountPoint = "/repos";
device = "storage:/repos";
fsType = "nfs";
options = "bootwait";
fsType = "nfs";
}
];