wok view nfs-utils/stuff/etc/init.d/nfsd @ rev 25551

nfs-utils: make nfsd work on first start too
author Hans-G?nter Theisgen
date Thu Apr 06 10:52:37 2023 +0100 (13 months ago)
parents 2994fe300985
children
line source
1 #!/bin/sh
2 # /etc/init.d/nfsd: Start, stop and restart NFS daemon on SliTaz, at boot
3 # time or with the command line.
4 #
5 # To start daemon at boot time, just put the right name in the $RUN_DAEMONS
6 # variable of /etc/rcS.conf.
7 #
9 . /etc/init.d/rc.functions
11 NAME=NFSd
12 DESC="$(_ '%s daemon' NFS)"
13 DAEMON=/usr/sbin/rpc.nfsd
14 PID_FILE=/var/run/nfsd.pid
15 OPTIONS="8" # start 8 threads, default is 1 if omitted
16 . /etc/daemons.conf
17 [ -z "$NFSD_OPTIONS" ] || OPTIONS="$NFSD_OPTIONS"
19 case "$1" in
20 (start)
21 if active_pidfile $PID_FILE nfsd
22 then
23 _ '%s is already running.' $NAME
24 exit 1
25 fi
26 action 'Starting %s: %s...' "$DESC" $NAME
27 # Make sure module nfsd is loaded:
28 modprobe nfsd
29 # Mount nfsd when not already mounted:
30 mount|grep -q /proc/fs/nfsd ||
31 mount -t nfsd nfsd /proc/fs/nfsd
32 # Start rpcbind when not already running:
33 [ -n "$(pidof rpcbind)" ] || rpcbind
34 # Export directories specified in /etc/exports:
35 /usr/sbin/exportfs -r
36 # Start nfsd:
37 $DAEMON $OPTIONS
38 p=$(pidof nfsd)
39 echo "${p%% *}" > $PID_FILE
40 # Start RPC mount daemon:
41 /usr/sbin/rpc.mountd
42 status
43 ;;
44 (stop)
45 if ! active_pidfile $PID_FILE nfsd
46 then
47 _ '%s is not running.' $NAME
48 exit 1
49 fi
50 action 'Stopping %s: %s...' "$DESC" $NAME
51 # Stop RPC mount daemon:
52 killall -q -KILL rpc.mountd
53 # Stop all threads of nfsd:
54 p=$(pidof nfsd)
55 # remove first pid, supposing it is own pid:
56 p=${p#* }
57 kill -KILL $p
58 # Unexport all exported directories:
59 /usr/sbin/exportfs -au
60 # flush kernel's export table:
61 /usr/sbin/exportfs -f
62 status
63 ;;
64 (restart)
65 if ! active_pidfile $PID_FILE nfsd
66 then
67 _ '%s is not running.' $NAME
68 exit 1
69 fi
70 action 'Restarting %s: %s...' "$DESC" $NAME
71 # Stop RPC mount daemon:
72 killall -q -KILL rpc.mountd
73 # Stop all instances of nfsd:
74 p=$(pidof nfsd)
75 # remove first pid, supposing it is own pid:
76 p=${p#* }
77 kill -KILL $p
78 # Unexport all exported directories:
79 /usr/sbin/exportfs -au
80 # flush kernel's export table:
81 /usr/sbin/exportfs -f
82 # Wait before starting:
83 sleep 2
84 # Export directories specified in /etc/exports:
85 /usr/sbin/exportfs -r
86 # Start nfsd:
87 $DAEMON $OPTIONS
88 p=$(pidof nfsd)
89 echo "${p%% *}" > $PID_FILE
90 # Start RPC mount daemon:
91 /usr/sbin/rpc.mountd
92 status
93 ;;
94 (*)
95 emsg "<n><b>$(_ 'Usage:')</b> $0 [start|stop|restart]"
96 newline
97 exit 1
98 ;;
99 esac
101 exit 0