I reworked the nfs upstart jobs, so they work better on the events of interest of nixos.

Related to http://yellowgrass.org/issue/NixOS/109 .


svn path=/nixos/trunk/; revision=31103
This commit is contained in:
Lluís Batlle i Rossell 2011-12-26 16:06:20 +00:00
parent cf36b3db80
commit 2c77b292a6
1 changed files with 52 additions and 26 deletions

View File

@ -10,6 +10,31 @@ let
exports = pkgs.writeText "exports" cfg.server.exports; exports = pkgs.writeText "exports" cfg.server.exports;
/*
Description at http://nfs.sourceforge.net/nfs-howto/ar01s03.html :
"If your distribution does not include them in the startup scripts, then then
you should add them, configured to start in the following order:
rpc.portmap
rpc.mountd, rpc.nfsd
rpc.statd, rpc.lockd (if necessary), and
rpc.rquotad"
I tried to mimic that with upstart, playing with stopping/stopped/started/starting
events.
I consider two scenarios:
- Starting at boot. Then, portmap will emit a started event.
- "restart nfs-kernel-exports". Then, portmap will not emit anything. Due
to the comment in postStart, this will happen on nixos-rebuild if
the exportfs file changed.
From these scenarios, I came up with the startOn and stopOn at the time of commiting
this comment.
*/
in in
{ {
@ -94,13 +119,35 @@ in
description = "Kernel NFS server"; description = "Kernel NFS server";
startOn = "started network-interfaces"; startOn = "started network-interfaces and started portmap";
postStart =
''
# exports file is ${exports}
# keep this comment so that this job is restarted whenever exports changes!
exportfs -ra
'';
};
}
// optionalAttrs cfg.server.enable
{ nfs_kernel_nfsd =
{ name = "nfs-kernel-nfsd";
description = "Kernel NFS server";
startOn = "starting nfs-kernel-exports or started portmap";
stopOn = "stopped nfs-kernel-statd or stopping portmap";
preStart = preStart =
'' ''
export PATH=${pkgs.nfsUtils}/sbin:$PATH export PATH=${pkgs.nfsUtils}/sbin:$PATH
mkdir -p /var/lib/nfs mkdir -p /var/lib/nfs
# Create a state directory required by NFSv4.
mkdir -p /var/lib/nfs/v4recovery
# rpc.nfsd needs the kernel support
${config.system.sbin.modprobe}/sbin/modprobe nfsd || true ${config.system.sbin.modprobe}/sbin/modprobe nfsd || true
${pkgs.sysvtools}/bin/mountpoint -q /proc/fs/nfsd \ ${pkgs.sysvtools}/bin/mountpoint -q /proc/fs/nfsd \
@ -116,27 +163,6 @@ in
'' ''
} }
# exports file is ${exports}
# keep this comment so that this job is restarted whenever exports changes!
exportfs -ra
'';
};
}
// optionalAttrs cfg.server.enable
{ nfs_kernel_nfsd =
{ name = "nfs-kernel-nfsd";
description = "Kernel NFS server";
startOn = "started nfs-kernel-exports and started nfs-kernel-mountd and started nfs-kernel-statd and started portmap";
stopOn = "stopping nfs-kernel-exports";
preStart =
''
# Create a state directory required by NFSv4.
mkdir -p /var/lib/nfs/v4recovery
${pkgs.nfsUtils}/sbin/rpc.nfsd \ ${pkgs.nfsUtils}/sbin/rpc.nfsd \
${if cfg.server.hostName != null then "-H ${cfg.server.hostName}" else ""} \ ${if cfg.server.hostName != null then "-H ${cfg.server.hostName}" else ""} \
${builtins.toString cfg.server.nproc} ${builtins.toString cfg.server.nproc}
@ -152,8 +178,8 @@ in
description = "Kernel NFS server - mount daemon"; description = "Kernel NFS server - mount daemon";
startOn = "started portmap and started nfs-kernel-exports"; startOn = "starting nfs-kernel-exports or started portmap";
stopOn = "stopped nfs-kernel-nfsd"; stopOn = "stopped nfs-kernel-statd";
daemonType = "fork"; daemonType = "fork";
@ -167,8 +193,8 @@ in
description = "Kernel NFS server - Network Status Monitor"; description = "Kernel NFS server - Network Status Monitor";
startOn = "started portmap"; startOn = "started nfs-kernel-mountd and started nfs-kernel-nfsd";
stopOn = "never"; stopOn = "stopping nfs-kernel-exports or stopping portmap";
preStart = preStart =
'' ''