cornucopia: bump SRCREV
[openembedded.git] / recipes / nfs-utils / nfs-utils-1.1.2 / nfsserver
blobb4c7662ce0986a99fe007afdb95824c65b53f3ac
1 #!/bin/sh
3 # Startup script for nfs-utils
6 # The environment variable NFS_SERVERS may be set in /etc/default/nfsd
7 # Other control variables may be overridden here too
8 test -r /etc/default/nfsd && . /etc/default/nfsd
10 # Location of executables:
11 test -x "$NFS_MOUNTD" || NFS_MOUNTD=/usr/sbin/rpc.mountd
12 test -x "$NFS_NFSD" || NFS_NFSD=/usr/sbin/rpc.nfsd
13 test -x "$NFS_STATD" || NFS_STATD=/usr/sbin/rpc.statd
15 # The user mode program must also exist (it just starts the kernel
16 # threads using the kernel module code).
17 test -x "$NFS_MOUNTD" || exit 0
18 test -x "$NFS_NFSD" || exit 0
20 # Default is 8 threads, value is settable between 1 and the truely
21 # ridiculous 99
22 test "$NFS_SERVERS" -gt 0 && test "$NFS_SERVERS" -lt 100 || NFS_SERVERS=8
24 # The default state directory is /var/lib/nfs
25 test -n "$NFS_STATEDIR" || NFS_STATEDIR=/var/lib/nfs
27 #----------------------------------------------------------------------
28 # Startup and shutdown functions.
29 # Actual startup/shutdown is at the end of this file.
30 #directories
31 create_directories(){
32 echo -n 'creating NFS state directory: '
33 mkdir -p "$NFS_STATEDIR"
34 ( cd "$NFS_STATEDIR"
35 umask 077
36 mkdir -p sm sm.bak
37 test -w sm/state || {
38 rm -f sm/state
39 :>sm/state
41 umask 022
42 for file in xtab etab smtab rmtab
44 test -w "$file" || {
45 rm -f "$file"
46 :>"$file"
48 done
50 echo done
52 #mountd
53 start_mountd(){
54 echo -n 'starting mountd: '
55 start-stop-daemon --start --exec "$NFS_MOUNTD" -- "-f /etc/exports $@"
56 echo done
58 stop_mountd(){
59 echo -n 'stopping mountd: '
60 start-stop-daemon --stop --quiet --exec "$NFS_MOUNTD"
61 echo done
64 #nfsd
65 start_nfsd(){
66 echo -n "starting $1 nfsd kernel threads: "
67 start-stop-daemon --start --exec "$NFS_NFSD" -- "$@"
68 echo done
70 delay_nfsd(){
71 for delay in 0 1 2 3 4 5 6 7 8 9
73 if pidof nfsd >/dev/null
74 then
75 echo -n .
76 sleep 1
77 else
78 return 0
80 done
81 return 1
83 stop_nfsd(){
84 # WARNING: this kills any process with the executable
85 # name 'nfsd'.
86 echo -n 'stopping nfsd: '
87 start-stop-daemon --stop --quiet --signal 1 --name nfsd
88 if delay_nfsd || {
89 echo failed
90 echo ' using signal 9: '
91 start-stop-daemon --stop --quiet --signal 9 --name nfsd
92 delay_nfsd
94 then
95 echo done
96 # This will remove, recursively, dependencies
97 echo -n 'removing nfsd kernel module: '
98 if modprobe -r nfsd
99 then
100 echo done
101 else
102 echo failed
104 else
105 echo failed
109 #statd
110 start_statd(){
111 echo -n "starting statd: "
112 start-stop-daemon --start --exec "$NFS_STATD"
113 echo done
115 stop_statd(){
116 # WARNING: this kills any process with the executable
117 # name 'statd'.
118 echo -n 'stopping statd: '
119 start-stop-daemon --stop --quiet --signal 1 --name statd
120 echo done
122 #----------------------------------------------------------------------
124 # supported options:
125 # start
126 # stop
127 # reload: reloads the exports file
128 # restart: stops and starts mountd
129 #FIXME: need to create the /var/lib/nfs/... directories
130 case "$1" in
131 start) create_directories
132 start_nfsd "$NFS_SERVERS"
133 start_mountd
134 start_statd
135 test -r /etc/exports && exportfs -a;;
136 stop) exportfs -ua
137 stop_statd
138 stop_mountd
139 stop_nfsd;;
140 reload) test -r /etc/exports && exportfs -r;;
141 restart)exportfs -ua
142 stop_mountd
143 stop_statd
144 # restart does not restart the kernel threads,
145 # only the user mode processes
146 start_mountd
147 start_statd
148 test -r /etc/exports && exportfs -a;;
149 esac