mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
* Fix the NFS Upstart dependencies. Mountd is now started before
nfsd, as suggested by the nfs-utils README. Also, rather than relying on Upstart events (which have all sorts of problems, especially if you have jobs that have multiple dependencies), we know just let jobs start their on prerequisites. That is, nfsd starts mountd in its preStart script; mountd starts statd; statd starts portmap. Likewise, mountall starts statd to ensure that it can mount NFS filesystems. This means that doing something like "start nfsd" from the command line will Do The Right Thing and start the dependencies of nfsd. svn path=/nixos/trunk/; revision=33172
This commit is contained in:
parent
823471a100
commit
a395e46192
4 changed files with 60 additions and 59 deletions
|
@ -413,6 +413,8 @@ sub shutdown {
|
||||||
sub crash {
|
sub crash {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
return unless $self->{booted};
|
return unless $self->{booted};
|
||||||
|
|
||||||
|
$self->log("forced crash");
|
||||||
|
|
||||||
$self->sendMonitorCommand("quit");
|
$self->sendMonitorCommand("quit");
|
||||||
|
|
||||||
|
|
|
@ -74,44 +74,64 @@ in
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config =
|
config = {
|
||||||
mkAssert
|
|
||||||
(cfg.client.enable || cfg.server.enable -> config.services.portmap.enable) "
|
|
||||||
Please enable portmap (services.portmap.enable) to use nfsd.
|
|
||||||
" {
|
|
||||||
|
|
||||||
services.portmap.enable = mkAlways (cfg.client.enable || cfg.server.enable);
|
services.portmap.enable = cfg.client.enable || cfg.server.enable;
|
||||||
|
|
||||||
|
environment.systemPackages = mkIf cfg.server.enable [ pkgs.nfsUtils ];
|
||||||
|
|
||||||
environment.etc = mkIf cfg.server.enable (singleton
|
environment.etc = mkIf cfg.server.enable (singleton
|
||||||
{ source = exports;
|
{ source = exports;
|
||||||
target = "exports";
|
target = "exports";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
boot.kernelModules = mkIf cfg.server.enable [ "nfsd" ];
|
||||||
|
|
||||||
jobs =
|
jobs =
|
||||||
optionalAttrs cfg.server.enable
|
optionalAttrs cfg.server.enable
|
||||||
{ nfsd =
|
{ nfsd =
|
||||||
{ description = "Kernel NFS server";
|
{ description = "Kernel NFS server";
|
||||||
|
|
||||||
startOn = "started portmap";
|
startOn = "started networking";
|
||||||
stopOn = "stopped statd";
|
|
||||||
|
path = [ pkgs.nfsUtils ];
|
||||||
|
|
||||||
preStart =
|
preStart =
|
||||||
''
|
''
|
||||||
export PATH=${pkgs.nfsUtils}/sbin:$PATH
|
start portmap || true
|
||||||
mkdir -p /var/lib/nfs
|
start mountd || true
|
||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
# exports file is ${exports}
|
rpc.nfsd \
|
||||||
# keep this comment so that this job is restarted whenever exports changes!
|
${if cfg.server.hostName != null then "-H ${cfg.server.hostName}" else ""} \
|
||||||
${pkgs.nfsUtils}/sbin/exportfs -ra
|
${builtins.toString cfg.server.nproc}
|
||||||
|
'';
|
||||||
# rpc.nfsd needs the kernel support
|
|
||||||
${config.system.sbin.modprobe}/sbin/modprobe nfsd || true
|
|
||||||
|
|
||||||
${pkgs.sysvtools}/bin/mountpoint -q /proc/fs/nfsd \
|
postStop = "rpc.nfsd 0";
|
||||||
|| ${pkgs.utillinux}/bin/mount -t nfsd none /proc/fs/nfsd
|
|
||||||
|
postStart =
|
||||||
|
''
|
||||||
|
start statd || true
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// optionalAttrs cfg.server.enable
|
||||||
|
{ mountd =
|
||||||
|
{ description = "Kernel NFS server - mount daemon";
|
||||||
|
|
||||||
|
path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ];
|
||||||
|
|
||||||
|
preStart =
|
||||||
|
''
|
||||||
|
start portmap || true
|
||||||
|
|
||||||
|
mkdir -p /var/lib/nfs
|
||||||
|
touch /var/lib/nfs/rmtab
|
||||||
|
|
||||||
|
mountpoint -q /proc/fs/nfsd || mount -t nfsd none /proc/fs/nfsd
|
||||||
|
|
||||||
${optionalString cfg.server.createMountPoints
|
${optionalString cfg.server.createMountPoints
|
||||||
''
|
''
|
||||||
|
@ -123,25 +143,14 @@ in
|
||||||
''
|
''
|
||||||
}
|
}
|
||||||
|
|
||||||
${pkgs.nfsUtils}/sbin/rpc.nfsd \
|
# exports file is ${exports}
|
||||||
${if cfg.server.hostName != null then "-H ${cfg.server.hostName}" else ""} \
|
# keep this comment so that this job is restarted whenever exports changes!
|
||||||
${builtins.toString cfg.server.nproc}
|
exportfs -ra
|
||||||
'';
|
'';
|
||||||
|
|
||||||
postStop = "${pkgs.nfsUtils}/sbin/rpc.nfsd 0";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// optionalAttrs cfg.server.enable
|
|
||||||
{ mountd =
|
|
||||||
{ description = "Kernel NFS server - mount daemon";
|
|
||||||
|
|
||||||
startOn = "started nfsd";
|
|
||||||
stopOn = "stopped statd";
|
|
||||||
|
|
||||||
daemonType = "fork";
|
daemonType = "fork";
|
||||||
|
|
||||||
exec = "${pkgs.nfsUtils}/sbin/rpc.mountd -f /etc/exports";
|
exec = "rpc.mountd -f /etc/exports";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,24 +158,22 @@ in
|
||||||
{ statd =
|
{ statd =
|
||||||
{ description = "Kernel NFS server - Network Status Monitor";
|
{ description = "Kernel NFS server - Network Status Monitor";
|
||||||
|
|
||||||
startOn = if cfg.server.enable then
|
path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ];
|
||||||
"started mountd and started nfsd"
|
|
||||||
else
|
stopOn = "never"; # needed during shutdown
|
||||||
"started portmap";
|
|
||||||
stopOn = "stopping nfsd";
|
|
||||||
|
|
||||||
preStart =
|
preStart =
|
||||||
''
|
''
|
||||||
|
start portmap || true
|
||||||
mkdir -p /var/lib/nfs
|
mkdir -p /var/lib/nfs
|
||||||
mkdir -p /var/lib/nfs/sm
|
mkdir -p /var/lib/nfs/sm
|
||||||
mkdir -p /var/lib/nfs/sm.bak
|
mkdir -p /var/lib/nfs/sm.bak
|
||||||
|
sm-notify -d
|
||||||
'';
|
'';
|
||||||
|
|
||||||
daemonType = "fork";
|
daemonType = "fork";
|
||||||
|
|
||||||
exec = "${pkgs.nfsUtils}/sbin/rpc.statd --no-notify";
|
exec = "rpc.statd --no-notify";
|
||||||
|
|
||||||
postStart = "${pkgs.nfsUtils}/sbin/sm-notify -d";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ in
|
||||||
startOn = "started network-interfaces";
|
startOn = "started network-interfaces";
|
||||||
stopOn = "never";
|
stopOn = "never";
|
||||||
|
|
||||||
daemonType = "fork";
|
daemonType = "fork"; # needed during shutdown
|
||||||
|
|
||||||
path = [ portmap pkgs.netcat ];
|
path = [ portmap pkgs.netcat ];
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ let
|
||||||
[ { mountPoint = "/data";
|
[ { mountPoint = "/data";
|
||||||
device = "server:/data";
|
device = "server:/data";
|
||||||
fsType = "nfs";
|
fsType = "nfs";
|
||||||
options = "bootwait";
|
options = "bootwait,vers=3";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
@ -34,11 +34,9 @@ in
|
||||||
|
|
||||||
testScript =
|
testScript =
|
||||||
''
|
''
|
||||||
startAll;
|
$server->waitForJob("nfsd");
|
||||||
|
|
||||||
$server->waitForJob("nfs-kernel-nfsd");
|
startAll;
|
||||||
$server->waitForJob("nfs-kernel-mountd");
|
|
||||||
$server->waitForJob("nfs-kernel-statd");
|
|
||||||
|
|
||||||
$client1->waitForJob("tty1"); # depends on filesystems
|
$client1->waitForJob("tty1"); # depends on filesystems
|
||||||
$client1->succeed("echo bla > /data/foo");
|
$client1->succeed("echo bla > /data/foo");
|
||||||
|
@ -48,15 +46,11 @@ in
|
||||||
$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 the ‘nfs-kernel-exports’ job works
|
# Test whether restarting ‘nfsd’ works correctly.
|
||||||
# correctly. In Upstart 0.6.7 this fails because the jobs that
|
$server->succeed("stop nfsd; start nfsd");
|
||||||
# depend on ‘nfs-kernel-exports’ are stopped but not restarted.
|
$client2->succeed("echo bla >> /data/bar"); # will take 90 seconds due to the NFS grace period
|
||||||
$server->succeed("restart nfs-kernel-exports");
|
|
||||||
$client2->succeed("echo bla >> /data/bar");
|
|
||||||
|
|
||||||
# Test whether we can get a lock. !!! This step takes about 90
|
# Test whether we can get a lock.
|
||||||
# seconds because the NFS server waits that long after booting
|
|
||||||
# before accepting new locks.
|
|
||||||
$client2->succeed("time flock -n -s /data/lock true");
|
$client2->succeed("time flock -n -s /data/lock true");
|
||||||
|
|
||||||
# Test locking: client 1 acquires an exclusive lock, so client 2
|
# Test locking: client 1 acquires an exclusive lock, so client 2
|
||||||
|
@ -78,9 +72,7 @@ in
|
||||||
$client1->succeed("touch /data/xyzzy");
|
$client1->succeed("touch /data/xyzzy");
|
||||||
$client1->fail("time flock -n -s /data/lock true");
|
$client1->fail("time flock -n -s /data/lock true");
|
||||||
|
|
||||||
# Test whether unmounting during shutdown happens quickly. This
|
# Test whether unmounting during shutdown happens quickly.
|
||||||
# requires portmap and statd to keep running during the
|
|
||||||
# shutdown.
|
|
||||||
my $t1 = time;
|
my $t1 = time;
|
||||||
$client1->shutdown;
|
$client1->shutdown;
|
||||||
my $duration = time - $t1;
|
my $duration = time - $t1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue