Package: nfs-kernel-server Version: 1:1.2.8-9 The systemd service unit file for `nfs-kernel-server` incorrectly reports the service status as "active" even when the NFS server is *not* running (e.g., empty exports file).
This causes scripts (e.g., Ansible) that use `systemctl status` to check for the NFS server to fail in a way that is difficult to debug because the actual reported error might be in a loosely-related task (e.g., when doing `exportfs -r` or when mounting fs from a client). Steps to reproduce on a Debian "jessie" VM: * starting from a basic "jessie" install, install the `nfs-kernel-server`:: debian@debian-nfs-bug:~$ sudo apt install nfs-kernel-server [...] The following extra packages will be installed: libevent-2.0-5 libldap-2.4-2 libnfsidmap2 libsasl2-2 libsasl2-modules libsasl2-modules-db libtirpc1 nfs-common rpcbind Suggested packages: libsasl2-modules-otp libsasl2-modules-ldap libsasl2-modules-sql libsasl2-modules-gssapi-mit libsasl2-modules-gssapi-heimdal open-iscsi watchdog The following NEW packages will be installed: libevent-2.0-5 libldap-2.4-2 libnfsidmap2 libsasl2-2 libsasl2-modules libsasl2-modules-db libtirpc1 nfs-common nfs-kernel-server rpcbind 0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded. Need to get 1123 kB of archives. After this operation, 3018 kB of additional disk space will be used. Do you want to continue? [Y/n] Get:1 http://http.debian.net/debian/ jessie/main libevent-2.0-5 amd64 2.0.21-stable-2 [152 kB] [...] Setting up libnfsidmap2:amd64 (0.25-5) ... Setting up libtirpc1:amd64 (0.2.5-1) ... Setting up rpcbind (0.2.1-6+deb8u1) ... Setting up nfs-common (1:1.2.8-9) ... Creating config file /etc/idmapd.conf with new version Adding system user `statd' (UID 106) ... Adding new user `statd' (UID 106) with group `nogroup' ... Not creating home directory `/var/lib/nfs'. Setting up libsasl2-modules:amd64 (2.1.26.dfsg1-13+deb8u1) ... Setting up nfs-kernel-server (1:1.2.8-9) ... Creating config file /etc/exports with new version Creating config file /etc/default/nfs-kernel-server with new version Processing triggers for libc-bin (2.19-18+deb8u6) ... Processing triggers for systemd (215-17+deb8u5) ... * note that the NFS server has *not* been started yet, as the rpcbind daemon does not know about it:: debian@debian-nfs-bug:~$ sudo rpcinfo -p program vers proto port service 100000 4 tcp 111 portmapper 100000 3 tcp 111 portmapper 100000 2 tcp 111 portmapper 100000 4 udp 111 portmapper 100000 3 udp 111 portmapper 100000 2 udp 111 portmapper 100024 1 udp 56360 status 100024 1 tcp 39499 status Still, `systemctl status` reports it already as loaded/active:: debian@debian-nfs-bug:~$ sudo systemctl status nfs-kernel-server.service * nfs-kernel-server.service - LSB: Kernel NFS server support Loaded: loaded (/etc/init.d/nfs-kernel-server) Active: active (exited) since Tue 2016-12-06 12:12:58 UTC; 1min 13s ago Dec 06 12:12:58 debian-nfs-bug nfs-kernel-server[1544]: Not starting NFS kernel daemon: no exports. ... (warning). Dec 06 12:12:58 debian-nfs-bug systemd[1]: Started LSB: Kernel NFS server support. * now add an export and try to start it again:: debian@debian-nfs-bug:~$ echo "/home localhost(rw,async.no_subtree_check)" | sudo tee -a /etc/exports /home localhost(rw,async.no_subtree_check) debian@debian-nfs-bug:~$ sudo systemctl start nfs-kernel-server (last command produces no output) * `systemctl status` reports the server as loaded/active (green on terminal, so "ok"):: debian@debian-nfs-bug:~$ sudo systemctl status nfs-kernel-server.service * nfs-kernel-server.service - LSB: Kernel NFS server support Loaded: loaded (/etc/init.d/nfs-kernel-server) Active: active (exited) since Tue 2016-12-06 12:12:58 UTC; 1min 36s ago Dec 06 12:12:58 debian-nfs-bug nfs-kernel-server[1544]: Not starting NFS kernel daemon: no exports. ... (warning). Dec 06 12:12:58 debian-nfs-bug systemd[1]: Started LSB: Kernel NFS server support. Dec 06 12:14:33 debian-nfs-bug systemd[1]: Started LSB: Kernel NFS server support. * still `exportfs -r` fails with a strange error message (due to `/proc/fs/nfsd` not being mounted) and the NFS server is not running nor registered with rpcbind/portmapper:: debian@debian-nfs-bug:~$ sudo exportfs -r exportfs: localhost:/home: Function not implemented debian@debian-nfs-bug:~$ sudo showmount -e localhost clnt_create: RPC: Program not registered debian@debian-nfs-bug:~$ sudo rpcinfo -p program vers proto port service 100000 4 tcp 111 portmapper 100000 3 tcp 111 portmapper 100000 2 tcp 111 portmapper 100000 4 udp 111 portmapper 100000 3 udp 111 portmapper 100000 2 udp 111 portmapper 100024 1 udp 56360 status 100024 1 tcp 39499 status On the other hand, `systemctl restart nfs-kernel-server` (or a reboot) does actually start the NFS server. System information: $ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 8.6 (jessie) Release: 8.6 Codename: jessie $ dpkg -l nfs-kernel-server nfs-common linux-image-3.16.0-4-amd64 Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-=========================================-=========================-=========================-======================================================================================= ii linux-image-3.16.0-4-amd64 3.16.36-1+deb8u1 amd64 Linux 3.16 for 64-bit PCs ii nfs-common 1:1.2.8-9 amd64 NFS support files common to client and server ii nfs-kernel-server 1:1.2.8-9 amd64 support for NFS kernel server $ uname -a Linux debian-nfs-bug 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u1 (2016-09-03) x86_64 GNU/Linux Thanks, Riccardo