`systemclt kill nfs-server.service` doesn't kill nfsd threads.

Solution Verified - Updated -

Issue

  • systemclt kill nfs-server.service doesn't kill nfsd threads.
# ps aux | grep nfsd
root     13070  0.0  0.0      0     0 ?        S<   19:47   0:00 [nfsd4_callbacks]
root     13076  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13077  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13078  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13079  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13080  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13081  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13082  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13083  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13221  0.0  0.0 112660   976 pts/2    S+   19:49   0:00 grep --color=auto nfsd
# systemctl kill nfs-server.service
# ps aux | grep nfsd
root     13070  0.0  0.0      0     0 ?        S<   19:47   0:00 [nfsd4_callbacks]
root     13076  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13077  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13078  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13079  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13080  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13081  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13082  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13083  0.0  0.0      0     0 ?        S    19:47   0:00 [nfsd]
root     13244  0.0  0.0 112660   976 pts/2    S+   19:50   0:00 grep --color=auto nfsd
  • According to man 1 systemctl, systemctl kill kills all (control and main) if we don't specify either of 'control' or 'main' with '--kill-who' as mentioned below:
       --kill-who=
           When used with kill, choose which processes to send a signal to. Must
           be one of main, control or all to select whether to kill only the main
           process, the control process or all processes of the unit. The main
           process of the unit is the one that defines the life-time of it. A
           control process of a unit is one that is invoked by the manager to
           induce state changes of it. For example, all processes started due to
           the ExecStartPre=, ExecStop= or ExecReload= settings of service units
           are control processes. Note that there is only one control process per
           unit at a time, as only one state change is executed at a time. For
           services of type Type=forking, the initial process started by the
           manager for ExecStart= is a control process, while the process
           ultimately forked off by that one is then considered the main process
           of the unit (if it can be determined). This is different for service
           units of other types, where the process forked off by the manager for
           ExecStart= is always the main process itself. A service unit consists
           of zero or one main process, zero or one control process plus any
           number of additional processes. Not all unit types manage processes of
           these types however. For example, for mount units, control processes
           are defined (which are the invocations of /usr/bin/mount and
           /usr/bin/umount), but no main process is defined. If omitted, defaults
           to all.
  • As mentioned above, control process is /usr/sbin/rpc.nfsd $RPCNFSDARGS specified in ExecStart. nfsd threads are forked from this control process. That means 'main' processes are nfsd threads.
# cat /usr/lib/systemd/system/nfs-server.service 
[Unit]
Description=NFS server and services
DefaultDependencies=no
Requires= network.target proc-fs-nfsd.mount
Requires= nfs-mountd.service
Wants=rpcbind.socket network-online.target
Wants=rpc-statd.service nfs-idmapd.service
Wants=rpc-statd-notify.service

After= network-online.target local-fs.target
After= proc-fs-nfsd.mount rpcbind.socket nfs-mountd.service
After= nfs-idmapd.service rpc-statd.service
Before= rpc-statd-notify.service

# GSS services dependencies and ordering
Wants=auth-rpcgss-module.service
After=rpc-gssd.service gssproxy.service

Wants=nfs-config.service
After=nfs-config.service

[Service]
EnvironmentFile=-/run/sysconfig/nfs-utils

Type=oneshot
RemainAfterExit=yes
ExecStartPre=-/usr/sbin/exportfs -r
ExecStartPre=-/bin/sh -c '/bin/kill -HUP `cat /run/gssproxy.pid`'
ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS
ExecStop=/usr/sbin/rpc.nfsd 0
ExecStopPost=/usr/sbin/exportfs -au
ExecStopPost=/usr/sbin/exportfs -f

ExecReload=-/usr/sbin/exportfs -r

[Install]
WantedBy=multi-user.target

Environment

  • Red Hat Enterprise Linux 7
  • systemd

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content