wok rev 25533

nfs-utils: made stop and restart working in /etc/init.d/nfsd
author Hans-G?nter Theisgen
date Tue Feb 28 14:41:52 2023 +0100 (14 months ago)
parents 54d60b77baf4
children 4e2caf3cd17b
files nfs-utils/stuff/etc/init.d/nfsd
line diff
     1.1 --- a/nfs-utils/stuff/etc/init.d/nfsd	Mon Feb 27 10:46:05 2023 +0000
     1.2 +++ b/nfs-utils/stuff/etc/init.d/nfsd	Tue Feb 28 14:41:52 2023 +0100
     1.3 @@ -5,79 +5,92 @@
     1.4  # To start daemon at boot time, just put the right name in the $RUN_DAEMONS
     1.5  # variable of /etc/rcS.conf.
     1.6  #
     1.7 +
     1.8  . /etc/init.d/rc.functions
     1.9  
    1.10  NAME=NFSd
    1.11  DESC="$(_ '%s daemon' NFS)"
    1.12  DAEMON=/usr/sbin/rpc.nfsd
    1.13  PID_FILE=/var/run/nfsd.pid
    1.14 -OPTION="8"
    1.15 -[ -n "$NFSD_OPTION" ] || OPTION="$NFSD_OPTION"
    1.16 -
    1.17 -stop_warning()
    1.18 -{
    1.19 -  echo "Warning: filesystems are unexported but nfsd and lockd processes are still alive..."
    1.20 -}
    1.21 +OPTIONS="8"	# start 8 threads, default is 1 if omitted
    1.22 +. /etc/daemons.conf
    1.23 +[ -z "$NFSD_OPTIONS" ] || OPTIONS="$NFSD_OPTIONS"
    1.24  
    1.25  case "$1" in
    1.26 -  start)
    1.27 -    if active_pidfile $PID_FILE nfsd ; then
    1.28 -      _ '%s is already running.' $NAME
    1.29 -      exit 1
    1.30 -    fi
    1.31 -    action 'Starting %s: %s...' "$DESC" $NAME
    1.32 -    portmap="$(pidof portmap)"
    1.33 -    if [ -n "$portmap" ]; then
    1.34 -      kill $portmap
    1.35 -      sleep 2
    1.36 -    fi
    1.37 -    [ -n "$(pidof rpcbind)" ] || rpcbind
    1.38 -    modprobe nfsd
    1.39 -    mount -t nfsd nfsd /proc/fs/nfsd 2>/dev/null
    1.40 -    /usr/sbin/exportfs -r
    1.41 -    $DAEMON $OPTION
    1.42 -    pidof nfsd | awk '{print $1}' > $PID_FILE
    1.43 -    /usr/sbin/rpc.mountd
    1.44 -    status
    1.45 -    ;;
    1.46 -  stop)
    1.47 -    if ! active_pidfile $PID_FILE nfsd ; then
    1.48 -      _ '%s is not running.' $NAME
    1.49 -      exit 1
    1.50 -    fi
    1.51 -    action 'Stopping %s: %s...' "$DESC" $NAME
    1.52 -    killall rpc.mountd
    1.53 -    killall nfsd
    1.54 -    killall lockd
    1.55 -    /usr/sbin/exportfs -au
    1.56 -    /usr/sbin/exportfs -f
    1.57 -    stop_warning	# FIXME
    1.58 -    rm $PID_FILE
    1.59 -    status
    1.60 -    ;;
    1.61 -  restart)
    1.62 -    if ! active_pidfile $PID_FILE nfsd ; then
    1.63 -      _ '%s is not running.' $NAME
    1.64 -      exit 1
    1.65 -    fi
    1.66 -    action 'Restarting %s: %s...' "$DESC" $NAME
    1.67 -    killall rpc.mountd
    1.68 -    killall nfsd
    1.69 -    killall lockd
    1.70 -    /usr/sbin/exportfs -au
    1.71 -    /usr/sbin/exportfs -f
    1.72 -    sleep 2
    1.73 -    /usr/sbin/exportfs -r
    1.74 -    $DAEMON $OPTION
    1.75 -    pidof nfsd | awk '{print $1}' > $PID_FILE
    1.76 -    /usr/sbin/rpc.mountd
    1.77 -    status
    1.78 -    ;;
    1.79 -  *)
    1.80 -    emsg "<n><b>$(_ 'Usage:')</b> $0 [start|stop|restart]"
    1.81 -    newline
    1.82 -    exit 1
    1.83 -    ;;
    1.84 +	(start)
    1.85 +		if active_pidfile $PID_FILE nfsd
    1.86 +		  then
    1.87 +			_ '%s is already running.' $NAME
    1.88 +			exit 1
    1.89 +		fi
    1.90 +		action 'Starting %s: %s...' "$DESC" $NAME
    1.91 +		# Start rpcbind when not already running:
    1.92 +		[ -n "$(pidof rpcbind)" ] || rpcbind
    1.93 +		# Export directories specified in /etc/exports:
    1.94 +		/usr/sbin/exportfs -r
    1.95 +		# Start nfsd:
    1.96 +		$DAEMON $OPTIONS
    1.97 +		p=$(pidof nfsd)
    1.98 +		echo "${p%% *}" > $PID_FILE
    1.99 +		# Start RPC mount daemon:
   1.100 +		/usr/sbin/rpc.mountd
   1.101 +		status
   1.102 +		;;
   1.103 +	(stop)
   1.104 +		if ! active_pidfile $PID_FILE nfsd
   1.105 +		  then
   1.106 +			_ '%s is not running.' $NAME
   1.107 +			exit 1
   1.108 +		fi
   1.109 +		action 'Stopping %s: %s...' "$DESC" $NAME
   1.110 +		# Stop RPC mount daemon:
   1.111 +		killall -q -KILL rpc.mountd
   1.112 +		# Stop all threads of nfsd:
   1.113 +		p=$(pidof nfsd)
   1.114 +		# remove first pid, supposing it is own pid:
   1.115 +		p=${p#* }
   1.116 +		kill -KILL $p
   1.117 +		# Unexport all exported directories:
   1.118 +		/usr/sbin/exportfs -au
   1.119 +		# flush kernel's export table:
   1.120 +		/usr/sbin/exportfs -f
   1.121 +		status
   1.122 +		;;
   1.123 +	(restart)
   1.124 +		if ! active_pidfile $PID_FILE nfsd
   1.125 +		  then
   1.126 +			_ '%s is not running.' $NAME
   1.127 +			exit 1
   1.128 +		fi
   1.129 +		action 'Restarting %s: %s...' "$DESC" $NAME
   1.130 +		# Stop RPC mount daemon:
   1.131 +		killall -q -KILL rpc.mountd
   1.132 +		# Stop all instances of nfsd:
   1.133 +		p=$(pidof nfsd)
   1.134 +		# remove first pid, supposing it is own pid:
   1.135 +		p=${p#* }
   1.136 +		kill -KILL $p
   1.137 +		# Unexport all exported directories:
   1.138 +		/usr/sbin/exportfs -au
   1.139 +		# flush kernel's export table:
   1.140 +		/usr/sbin/exportfs -f
   1.141 +		# Wait before starting:
   1.142 +		sleep 2
   1.143 +		# Export directories specified in /etc/exports:
   1.144 +		/usr/sbin/exportfs -r
   1.145 +		# Start nfsd:
   1.146 +		$DAEMON $OPTIONS
   1.147 +		p=$(pidof nfsd)
   1.148 +		echo "${p%% *}" > $PID_FILE
   1.149 +		# Start RPC mount daemon:
   1.150 +		/usr/sbin/rpc.mountd
   1.151 +		status
   1.152 +		;;
   1.153 +	(*)
   1.154 +		emsg "<n><b>$(_ 'Usage:')</b> $0 [start|stop|restart]"
   1.155 +		newline
   1.156 +		exit 1
   1.157 +		;;
   1.158  esac
   1.159  
   1.160  exit 0