# HG changeset patch # User Hans-G?nter Theisgen # Date 1677591712 -3600 # Node ID 2994fe300985b7518718a13fcee1571de8c40f04 # Parent 54d60b77baf47acfa4d89afd871e6a1bbcc1f8dd nfs-utils: made stop and restart working in /etc/init.d/nfsd diff -r 54d60b77baf4 -r 2994fe300985 nfs-utils/stuff/etc/init.d/nfsd --- a/nfs-utils/stuff/etc/init.d/nfsd Mon Feb 27 10:46:05 2023 +0000 +++ b/nfs-utils/stuff/etc/init.d/nfsd Tue Feb 28 14:41:52 2023 +0100 @@ -5,79 +5,92 @@ # To start daemon at boot time, just put the right name in the $RUN_DAEMONS # variable of /etc/rcS.conf. # + . /etc/init.d/rc.functions NAME=NFSd DESC="$(_ '%s daemon' NFS)" DAEMON=/usr/sbin/rpc.nfsd PID_FILE=/var/run/nfsd.pid -OPTION="8" -[ -n "$NFSD_OPTION" ] || OPTION="$NFSD_OPTION" - -stop_warning() -{ - echo "Warning: filesystems are unexported but nfsd and lockd processes are still alive..." -} +OPTIONS="8" # start 8 threads, default is 1 if omitted +. /etc/daemons.conf +[ -z "$NFSD_OPTIONS" ] || OPTIONS="$NFSD_OPTIONS" case "$1" in - start) - if active_pidfile $PID_FILE nfsd ; then - _ '%s is already running.' $NAME - exit 1 - fi - action 'Starting %s: %s...' "$DESC" $NAME - portmap="$(pidof portmap)" - if [ -n "$portmap" ]; then - kill $portmap - sleep 2 - fi - [ -n "$(pidof rpcbind)" ] || rpcbind - modprobe nfsd - mount -t nfsd nfsd /proc/fs/nfsd 2>/dev/null - /usr/sbin/exportfs -r - $DAEMON $OPTION - pidof nfsd | awk '{print $1}' > $PID_FILE - /usr/sbin/rpc.mountd - status - ;; - stop) - if ! active_pidfile $PID_FILE nfsd ; then - _ '%s is not running.' $NAME - exit 1 - fi - action 'Stopping %s: %s...' "$DESC" $NAME - killall rpc.mountd - killall nfsd - killall lockd - /usr/sbin/exportfs -au - /usr/sbin/exportfs -f - stop_warning # FIXME - rm $PID_FILE - status - ;; - restart) - if ! active_pidfile $PID_FILE nfsd ; then - _ '%s is not running.' $NAME - exit 1 - fi - action 'Restarting %s: %s...' "$DESC" $NAME - killall rpc.mountd - killall nfsd - killall lockd - /usr/sbin/exportfs -au - /usr/sbin/exportfs -f - sleep 2 - /usr/sbin/exportfs -r - $DAEMON $OPTION - pidof nfsd | awk '{print $1}' > $PID_FILE - /usr/sbin/rpc.mountd - status - ;; - *) - emsg "$(_ 'Usage:') $0 [start|stop|restart]" - newline - exit 1 - ;; + (start) + if active_pidfile $PID_FILE nfsd + then + _ '%s is already running.' $NAME + exit 1 + fi + action 'Starting %s: %s...' "$DESC" $NAME + # Start rpcbind when not already running: + [ -n "$(pidof rpcbind)" ] || rpcbind + # Export directories specified in /etc/exports: + /usr/sbin/exportfs -r + # Start nfsd: + $DAEMON $OPTIONS + p=$(pidof nfsd) + echo "${p%% *}" > $PID_FILE + # Start RPC mount daemon: + /usr/sbin/rpc.mountd + status + ;; + (stop) + if ! active_pidfile $PID_FILE nfsd + then + _ '%s is not running.' $NAME + exit 1 + fi + action 'Stopping %s: %s...' "$DESC" $NAME + # Stop RPC mount daemon: + killall -q -KILL rpc.mountd + # Stop all threads of nfsd: + p=$(pidof nfsd) + # remove first pid, supposing it is own pid: + p=${p#* } + kill -KILL $p + # Unexport all exported directories: + /usr/sbin/exportfs -au + # flush kernel's export table: + /usr/sbin/exportfs -f + status + ;; + (restart) + if ! active_pidfile $PID_FILE nfsd + then + _ '%s is not running.' $NAME + exit 1 + fi + action 'Restarting %s: %s...' "$DESC" $NAME + # Stop RPC mount daemon: + killall -q -KILL rpc.mountd + # Stop all instances of nfsd: + p=$(pidof nfsd) + # remove first pid, supposing it is own pid: + p=${p#* } + kill -KILL $p + # Unexport all exported directories: + /usr/sbin/exportfs -au + # flush kernel's export table: + /usr/sbin/exportfs -f + # Wait before starting: + sleep 2 + # Export directories specified in /etc/exports: + /usr/sbin/exportfs -r + # Start nfsd: + $DAEMON $OPTIONS + p=$(pidof nfsd) + echo "${p%% *}" > $PID_FILE + # Start RPC mount daemon: + /usr/sbin/rpc.mountd + status + ;; + (*) + emsg "$(_ 'Usage:') $0 [start|stop|restart]" + newline + exit 1 + ;; esac exit 0