Subversion Repositories configs

Rev

Rev 3 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 1
#!/bin/sh
2
#
3
# nfs           This shell script takes care of starting and stopping
4
#               the NFS services.
5
#
6
# chkconfig: - 30 60
7
# description: NFS is a popular protocol for file sharing across networks.
8
#              This service provides NFS server functionality, which is \
9
#              configured via the /etc/exports file.
10
# probe: true
11
# config: /etc/sysconfig/nfs
12
 
13
### BEGIN INIT INFO
14
# Provides: nfs
15
# Required-Start: $local_fs $network $syslog $rpcbind
16
# Required-Stop: $local_fs $network $syslog $rpcbind
17
# Default-Stop: 0 1 6
18
# Short-Description: Start up the NFS server sevice
19
# Description: NFS is a popular protocol for file sharing across networks \
20
#              This service provides NFS server functionality, \
21
#              which is configured via the /etc/exports file.
22
### END INIT INFO
23
 
24
 
25
# Source function library.
26
. /etc/rc.d/init.d/functions
27
 
28
# Source networking configuration.
29
[ -f /etc/sysconfig/network ] &&  . /etc/sysconfig/network
30
 
31
# Check for and source configuration file otherwise set defaults
32
[ -f /etc/sysconfig/nfs ] && . /etc/sysconfig/nfs
33
 
34
# Remote quota server
35
[ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad`
36
 
37
RETVAL=0
38
uid=`id | cut -d\( -f1 | cut -d= -f2`
39
 
40
# See how we were called.
41
case "$1" in
42
  start)
43
 
44
	# Check that networking is up.
45
	[ "${NETWORKING}" != "yes" ] && exit 6
46
 
47
	[ -x /usr/sbin/rpc.nfsd ] || exit 5
48
	[ -x /usr/sbin/rpc.mountd ] || exit 5
49
	[ -x /usr/sbin/exportfs ] || exit 5
50
 
51
	# Make sure the rpc.mountd is not already running.
52
	if status rpc.mountd > /dev/null ; then
53
		exit 0
54
	fi
55
 
56
	# Only root can start the service
57
	[ $uid -ne 0 ] && exit 4
58
 
59
	# Don't fail if /etc/exports doesn't exist; create a bare-bones
60
	# version and continue.
61
	[ -r /etc/exports ] || \
62
    	{ touch /etc/exports && chmod u+rw,g+r,o+r /etc/exports ; } || \
63
    	{ echo "/etc/exports does not exist" ; exit 0 ; }
64
 
65
	[ -z "$MOUNTD_NFS_V2" ] && MOUNTD_NFS_V2=default
66
	[ -z "$MOUNTD_NFS_V3" ] && MOUNTD_NFS_V3=default
67
 
68
	# Number of servers to be started by default
69
	[ -z "$RPCNFSDCOUNT" ] && RPCNFSDCOUNT=8
70
 
71
	# Start daemons.
72
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd start
73
 
74
	# Set the ports lockd should listen on
75
	if [ -n "$LOCKD_TCPPORT" -o -n "$LOCKD_UDPPORT" ]; then
76
		[ -x /sbin/modprobe ] && /sbin/modprobe lockd $LOCKDARG
77
		[ -n "$LOCKD_TCPPORT" ] && \
78
			/sbin/sysctl -w fs.nfs.nlm_tcpport=$LOCKD_TCPPORT >/dev/null 2>&1
79
		[ -n "$LOCKD_UDPPORT" ] && \
80
			/sbin/sysctl -w fs.nfs.nlm_udpport=$LOCKD_UDPPORT >/dev/null 2>&1
81
	fi
8 - 82
	[ -n "$NLM_GRACE_PERIOD" ] && {
83
		/sbin/sysctl -w fs.nfs.nlm_grace_period=$NLM_GRACE_PERIOD >/dev/null 2>&1
84
	}
3 - 85
 
86
	# Load the nfsd module so /proc/fs/nfsd will exist
87
	[ "$NFSD_MODULE" != "noload" -a -x /sbin/modprobe ] && {
88
		/sbin/modprobe nfsd
89
		[ -n "$RDMA_PORT" ] && /sbin/modprobe svcrdma
90
	}
91
	# Set v4 grace period if requested
92
	[ -n "$NFSD_V4_GRACE" ] && {
93
		echo "$NFSD_V4_GRACE" > /proc/fs/nfsd/nfsv4gracetime
94
	}
8 - 95
	# Set v4 lease period if requested
96
	[ -n "$NFSD_V4_LEASE" ] && {
97
		echo "$NFSD_V4_LEASE" > /proc/fs/nfsd/nfsv4leasetime
98
	}
99
 
3 - 100
	action $"Starting NFS services: " /usr/sbin/exportfs -r
101
 
102
	if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
103
	    echo -n $"Starting NFS quotas: "
104
		[ -n "$RQUOTAD_PORT" ] \
105
			&& RPCRQUOTADOPTS="$RPCRQUOTADOPTS -p $RQUOTAD_PORT"
106
	    daemon rpc.rquotad $RPCRQUOTADOPTS
107
		touch /var/lock/subsys/rpc.rquotad
108
		RETVAL=$?
109
	    echo
110
	fi
111
 
112
 
113
	[ -n "$MOUNTD_PORT" ] \
114
	&& RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
115
 
116
	case $MOUNTD_NFS_V1 in
117
	no|NO)
118
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 1" ;;
119
	esac
120
 
121
	case $MOUNTD_NFS_V2 in
122
	no|NO)
123
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 2" ;;
124
	esac
125
 
126
	case $MOUNTD_NFS_V3 in
127
	no|NO)
128
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3" ;;
129
	esac
130
 
131
	echo -n $"Starting NFS mountd: "
132
	daemon rpc.mountd $RPCMOUNTDOPTS
133
	RETVAL=$?
134
	echo
135
	touch /var/lock/subsys/rpc.mountd
136
	touch /var/lock/subsys/nfs
137
 
138
	echo -n $"Starting NFS daemon: "
139
	daemon rpc.nfsd $RPCNFSDARGS $RPCNFSDCOUNT
140
	RETVAL=$?
141
	echo
142
	[ $RETVAL -ne 0 ] && exit $RETVAL
143
 
144
	[ -n "$RDMA_PORT" ] && echo "rdma $RDMA_PORT" > /proc/fs/nfsd/portlist
145
 
146
	# Let's if we need to signal or start rpc.idmapd
147
	if [ -f /var/lock/subsys/rpc.idmapd ]; then
148
		killproc rpc.idmapd -1 # SIGHUP
149
	else
150
		/sbin/service rpcidmapd start
151
		touch /var/lock/subsys/nfs-rpcidmapd
152
	fi
153
 
154
	;;
155
  stop)
156
	# Only root can stop the service
157
	[ $uid -ne 0 ] && exit 4
158
 
159
	# Stop daemons.
160
	echo -n $"Shutting down NFS daemon: "
161
	killproc nfsd -2
162
	RETVAL=$?
163
	echo
164
 
165
	echo -n $"Shutting down NFS mountd: "
166
	killproc rpc.mountd
167
	rval=$?
168
	[ $RETVAL -eq 0 ] && RETVAL=$rval
169
	echo
170
	if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
171
		echo -n $"Shutting down NFS quotas: "
172
		killproc rpc.rquotad
173
		rval=$?
174
		[ $RETVAL -eq 0 ] && RETVAL=$rval
175
		echo
176
	fi
177
	# Reset the lockd ports if they were set
178
	if [ -n "$LOCKD_TCPPORT" ]; then
179
	    /sbin/sysctl -w fs.nfs.nlm_tcpport=0 >/dev/null 2>&1
180
	fi
181
	if [ -n "$LOCKD_UDPPORT" ]; then
182
	    /sbin/sysctl -w fs.nfs.nlm_udpport=0 >/dev/null 2>&1
183
	fi
8 - 184
	if [ -n "$NLM_GRACE_PERIOD" ]; then
185
		/sbin/sysctl -w fs.nfs.nlm_grace_period=0 >/dev/null 2>&1
186
	fi
3 - 187
	# Do it the last so that clients can still access the server
188
	# when the server is running.
189
	cnt=`/usr/sbin/exportfs -v | /usr/bin/wc -l`
190
	if [ $cnt -gt 0 ]; then
191
		action $"Shutting down NFS services: " /usr/sbin/exportfs -au
192
		rval=$?
193
		[ $RETVAL -eq 0 ] && RETVAL=$rval
194
	fi
195
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd stop
196
	[ -f /var/lock/subsys/nfs-rpcidmapd ] &&  /sbin/service rpcidmapd stop
197
	rm -f /var/lock/subsys/nfs
198
	rm -f /var/lock/subsys/nfs-rpcidmapd
199
	rm -f /var/lock/subsys/rpc.mountd
200
	rm -f /var/lock/subsys/rpc.rquotad
201
	;;
202
  status)
203
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd status
204
	status rpc.mountd
205
	RETVAL=$?
206
	status -l nfs nfsd
207
	rval=$?
208
	[ $RETVAL -eq 0 ] && RETVAL=$rval
209
	if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
210
		status rpc.rquotad
211
		rval=$?
212
		[ $RETVAL -eq 0 ] && RETVAL=$rval
213
	fi
214
	;;
215
  restart)
216
	$0 stop
217
	$0 start
218
	;;
219
  reload | force-reload)
220
	/usr/sbin/exportfs -r
221
	[ -f /var/lock/subsys/nfs ] && touch /var/lock/subsys/nfs
222
	;;
223
  probe)
224
	if [ ! -f /var/lock/subsys/nfs ] ; then
225
	  echo $"start"; exit 0
226
	fi
227
	/sbin/pidof rpc.mountd >/dev/null 2>&1; MOUNTD="$?"
228
	/sbin/pidof nfsd >/dev/null 2>&1; NFSD="$?"
229
	if [ $MOUNTD = 1 -o $NFSD = 1 ] ; then
230
	  echo $"restart"; exit 0
231
	fi
232
	if [ /etc/exports -nt /var/lock/subsys/nfs ] ; then
233
	  echo $"reload"; exit 0
234
	fi
235
	;;
236
  condrestart | try-restart)
237
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd condrestart
238
  	[ -f /var/lock/subsys/nfs ] && {
239
		$0 stop
240
		$0 start
241
		RETVAL=$?
242
	}
243
	;;
244
  condstop)
245
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd condstop
246
  	[ -f /var/lock/subsys/nfs ] && {
247
		$0 stop
248
		RETVAL=$?
249
	}
250
	;;
251
  *)
252
	echo $"Usage: nfs {start|stop|status|restart|reload|force-reload|condrestart|try-restart|condstop}"
253
	RETVAL=2
254
	;;
255
esac
256
 
257
exit $RETVAL