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/nfsserver164
1 files changed, 164 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..1ac6fec023
--- /dev/null
+++ b/meta/recipes-connectivity/nfs-utils/nfs-utils/nfsserver
@@ -0,0 +1,164 @@
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# Source function library.
18. /etc/init.d/functions
19#
20# The environment variable NFS_SERVERS may be set in /etc/default/nfsd
21# Other control variables may be overridden here too
22test -r /etc/default/nfsd && . /etc/default/nfsd
23#
24# Location of executables:
25test -x "$NFS_MOUNTD" || NFS_MOUNTD=/usr/sbin/rpc.mountd
26test -x "$NFS_NFSD" || NFS_NFSD=/usr/sbin/rpc.nfsd
27test -x "$NFS_STATD" || NFS_STATD=/usr/sbin/rpc.statd
28#
29# The user mode program must also exist (it just starts the kernel
30# threads using the kernel module code).
31test -x "$NFS_MOUNTD" || exit 0
32test -x "$NFS_NFSD" || exit 0
33#
34# Default is 8 threads, value is settable between 1 and the truely
35# ridiculous 99
36test "$NFS_SERVERS" != "" && test "$NFS_SERVERS" -gt 0 && test "$NFS_SERVERS" -lt 100 || NFS_SERVERS=8
37#
38# The default state directory is /var/lib/nfs
39test -n "$NFS_STATEDIR" || NFS_STATEDIR=/var/lib/nfs
40#
41#----------------------------------------------------------------------
42# Startup and shutdown functions.
43# Actual startup/shutdown is at the end of this file.
44#directories
45create_directories(){
46 echo -n 'creating NFS state directory: '
47 mkdir -p "$NFS_STATEDIR"
48 ( cd "$NFS_STATEDIR"
49 umask 077
50 mkdir -p sm sm.bak
51 test -w sm/state || {
52 rm -f sm/state
53 :>sm/state
54 }
55 umask 022
56 for file in xtab etab smtab rmtab
57 do
58 test -w "$file" || {
59 rm -f "$file"
60 :>"$file"
61 }
62 done
63 )
64 echo done
65}
66#mountd
67start_mountd(){
68 echo -n 'starting mountd: '
69 start-stop-daemon --start --exec "$NFS_MOUNTD" -- "-f /etc/exports $@"
70 echo done
71}
72stop_mountd(){
73 echo -n 'stopping mountd: '
74 start-stop-daemon --stop --quiet --exec "$NFS_MOUNTD"
75 echo done
76}
77#
78#nfsd
79start_nfsd(){
80 echo -n "starting $1 nfsd kernel threads: "
81 start-stop-daemon --start --exec "$NFS_NFSD" -- "$@"
82 echo done
83}
84delay_nfsd(){
85 for delay in 0 1 2 3 4 5 6 7 8 9
86 do
87 if pidof nfsd >/dev/null
88 then
89 echo -n .
90 sleep 1
91 else
92 return 0
93 fi
94 done
95 return 1
96}
97stop_nfsd(){
98 # WARNING: this kills any process with the executable
99 # name 'nfsd'.
100 echo -n 'stopping nfsd: '
101 start-stop-daemon --stop --quiet --signal 1 --name nfsd
102 if delay_nfsd || {
103 echo failed
104 echo ' using signal 9: '
105 start-stop-daemon --stop --quiet --signal 9 --name nfsd
106 delay_nfsd
107 }
108 then
109 echo done
110 else
111 echo failed
112 fi
113}
114
115#statd
116start_statd(){
117 echo -n "starting statd: "
118 start-stop-daemon --start --exec "$NFS_STATD"
119 echo done
120}
121stop_statd(){
122 # WARNING: this kills any process with the executable
123 # name 'statd'.
124 echo -n 'stopping statd: '
125 start-stop-daemon --stop --quiet --signal 1 --name statd
126 echo done
127}
128#----------------------------------------------------------------------
129#
130# supported options:
131# start
132# stop
133# reload: reloads the exports file
134# restart: stops and starts mountd
135#FIXME: need to create the /var/lib/nfs/... directories
136case "$1" in
137start) create_directories
138 start_nfsd "$NFS_SERVERS"
139 start_mountd
140 start_statd
141 test -r /etc/exports && exportfs -a;;
142stop) exportfs -ua
143 stop_statd
144 stop_mountd
145 stop_nfsd;;
146status)
147 status /usr/sbin/rpc.mountd
148 RETVAL=$?
149 status nfsd
150 rval=$?
151 [ $RETVAL -eq 0 ] && exit $rval
152 exit $RETVAL;;
153reload) test -r /etc/exports && exportfs -r;;
154restart)exportfs -ua
155 stop_mountd
156 stop_statd
157 # restart does not restart the kernel threads,
158 # only the user mode processes
159 start_mountd
160 start_statd
161 test -r /etc/exports && exportfs -a;;
162*) echo "Usage: $0 {start|stop|status|reload|restart}"
163 exit 1;;
164esac