summaryrefslogtreecommitdiffstats
path: root/meta/recipes-connectivity/nfs-utils/nfs-utils/nfsserver
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-connectivity/nfs-utils/nfs-utils/nfsserver')
-rw-r--r--meta/recipes-connectivity/nfs-utils/nfs-utils/nfsserver161
1 files changed, 161 insertions, 0 deletions
diff --git a/meta/recipes-connectivity/nfs-utils/nfs-utils/nfsserver b/meta/recipes-connectivity/nfs-utils/nfs-utils/nfsserver
new file mode 100644
index 0000000000..9d02e85848
--- /dev/null
+++ b/meta/recipes-connectivity/nfs-utils/nfs-utils/nfsserver
@@ -0,0 +1,161 @@
1#!/bin/sh
2### BEGIN INIT INFO
3# Provides: nfs-kernel-server
4# Required-Start: $remote_fs $portmap hwclock
5# Required-Stop: $remote_fs $portmap hwclock
6# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
8# Short-Description: Kernel NFS server support
9# Description: NFS is a popular protocol for file sharing across
10# TCP/IP networks. This service provides NFS server
11# functionality, which is configured via the
12# /etc/exports file.
13### END INIT INFO
14#
15# Startup script for nfs-utils
16#
17#
18# The environment variable NFS_SERVERS may be set in /etc/default/nfsd
19# Other control variables may be overridden here too
20test -r /etc/default/nfsd && . /etc/default/nfsd
21#
22# Location of executables:
23test -x "$NFS_MOUNTD" || NFS_MOUNTD=/usr/sbin/mountd
24test -x "$NFS_NFSD" || NFS_NFSD=/usr/sbin/nfsd
25test -x "$NFS_STATD" || NFS_STATD=/usr/sbin/statd
26#
27# The user mode program must also exist (it just starts the kernel
28# threads using the kernel module code).
29test -x "$NFS_MOUNTD" || exit 0
30test -x "$NFS_NFSD" || exit 0
31#
32# Default is 8 threads, value is settable between 1 and the truely
33# ridiculous 99
34test "$NFS_SERVERS" -gt 0 && test "$NFS_SERVERS" -lt 100 || NFS_SERVERS=8
35#
36# The default state directory is /var/lib/nfs
37test -n "$NFS_STATEDIR" || NFS_STATEDIR=/var/lib/nfs
38#
39#----------------------------------------------------------------------
40# Startup and shutdown functions.
41# Actual startup/shutdown is at the end of this file.
42#directories
43create_directories(){
44 echo -n 'creating NFS state directory: '
45 mkdir -p "$NFS_STATEDIR"
46 ( cd "$NFS_STATEDIR"
47 umask 077
48 mkdir -p sm sm.bak
49 test -w sm/state || {
50 rm -f sm/state
51 :>sm/state
52 }
53 umask 022
54 for file in xtab etab smtab rmtab
55 do
56 test -w "$file" || {
57 rm -f "$file"
58 :>"$file"
59 }
60 done
61 )
62 echo done
63}
64#mountd
65start_mountd(){
66 echo -n 'starting mountd: '
67 start-stop-daemon --start --exec "$NFS_MOUNTD" -- "-f /etc/exports $@"
68 echo done
69}
70stop_mountd(){
71 echo -n 'stopping mountd: '
72 start-stop-daemon --stop --quiet --exec "$NFS_MOUNTD"
73 echo done
74}
75#
76#nfsd
77start_nfsd(){
78 echo -n "starting $1 nfsd kernel threads: "
79 start-stop-daemon --start --exec "$NFS_NFSD" -- "$@"
80 echo done
81}
82delay_nfsd(){
83 for delay in 0 1 2 3 4 5 6 7 8 9
84 do
85 if pidof nfsd >/dev/null
86 then
87 echo -n .
88 sleep 1
89 else
90 return 0
91 fi
92 done
93 return 1
94}
95stop_nfsd(){
96 # WARNING: this kills any process with the executable
97 # name 'nfsd'.
98 echo -n 'stopping nfsd: '
99 start-stop-daemon --stop --quiet --signal 1 --name nfsd
100 if delay_nfsd || {
101 echo failed
102 echo ' using signal 9: '
103 start-stop-daemon --stop --quiet --signal 9 --name nfsd
104 delay_nfsd
105 }
106 then
107 echo done
108 # This will remove, recursively, dependencies
109 echo -n 'removing nfsd kernel module: '
110 if modprobe -r nfsd
111 then
112 echo done
113 else
114 echo failed
115 fi
116 else
117 echo failed
118 fi
119}
120
121#statd
122start_statd(){
123 echo -n "starting statd: "
124 start-stop-daemon --start --exec "$NFS_STATD"
125 echo done
126}
127stop_statd(){
128 # WARNING: this kills any process with the executable
129 # name 'statd'.
130 echo -n 'stopping statd: '
131 start-stop-daemon --stop --quiet --signal 1 --name statd
132 echo done
133}
134#----------------------------------------------------------------------
135#
136# supported options:
137# start
138# stop
139# reload: reloads the exports file
140# restart: stops and starts mountd
141#FIXME: need to create the /var/lib/nfs/... directories
142case "$1" in
143start) create_directories
144 start_nfsd "$NFS_SERVERS"
145 start_mountd
146 start_statd
147 test -r /etc/exports && exportfs -a;;
148stop) exportfs -ua
149 stop_statd
150 stop_mountd
151 stop_nfsd;;
152reload) test -r /etc/exports && exportfs -r;;
153restart)exportfs -ua
154 stop_mountd
155 stop_statd
156 # restart does not restart the kernel threads,
157 # only the user mode processes
158 start_mountd
159 start_statd
160 test -r /etc/exports && exportfs -a;;
161esac