Subversion Repositories configs

Rev

Rev 9 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 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
82
 
83
	# Load the nfsd module so /proc/fs/nfsd will exist
84
	[ "$NFSD_MODULE" != "noload" -a -x /sbin/modprobe ] && {
85
		/sbin/modprobe nfsd
86
		[ -n "$RDMA_PORT" ] && /sbin/modprobe svcrdma
87
	}
88
	# Set v4 grace period if requested
89
	[ -n "$NFSD_V4_GRACE" ] && {
90
		echo "$NFSD_V4_GRACE" > /proc/fs/nfsd/nfsv4gracetime
91
	}
92
	action $"Starting NFS services: " /usr/sbin/exportfs -r
93
 
94
	if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
95
	    echo -n $"Starting NFS quotas: "
96
		[ -n "$RQUOTAD_PORT" ] \
97
			&& RPCRQUOTADOPTS="$RPCRQUOTADOPTS -p $RQUOTAD_PORT"
98
	    daemon rpc.rquotad $RPCRQUOTADOPTS
99
		touch /var/lock/subsys/rpc.rquotad
100
		RETVAL=$?
101
	    echo
102
	fi
103
 
104
 
105
	[ -n "$MOUNTD_PORT" ] \
106
	&& RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
107
 
108
	case $MOUNTD_NFS_V1 in
109
	no|NO)
110
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 1" ;;
111
	esac
112
 
113
	case $MOUNTD_NFS_V2 in
114
	no|NO)
115
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 2" ;;
116
	esac
117
 
118
	case $MOUNTD_NFS_V3 in
119
	no|NO)
120
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3" ;;
121
	esac
122
 
123
	echo -n $"Starting NFS mountd: "
124
	daemon rpc.mountd $RPCMOUNTDOPTS
125
	RETVAL=$?
126
	echo
127
	touch /var/lock/subsys/rpc.mountd
128
	touch /var/lock/subsys/nfs
129
 
130
	echo -n $"Starting NFS daemon: "
131
	daemon rpc.nfsd $RPCNFSDARGS $RPCNFSDCOUNT
132
	RETVAL=$?
133
	echo
134
	[ $RETVAL -ne 0 ] && exit $RETVAL
135
 
136
	[ -n "$RDMA_PORT" ] && echo "rdma $RDMA_PORT" > /proc/fs/nfsd/portlist
137
 
138
	# Let's if we need to signal or start rpc.idmapd
139
	if [ -f /var/lock/subsys/rpc.idmapd ]; then
140
		killproc rpc.idmapd -1 # SIGHUP
141
	else
142
		/sbin/service rpcidmapd start
143
		touch /var/lock/subsys/nfs-rpcidmapd
144
	fi
145
 
146
	;;
147
  stop)
148
	# Only root can stop the service
149
	[ $uid -ne 0 ] && exit 4
150
 
151
	# Stop daemons.
152
	echo -n $"Shutting down NFS daemon: "
153
	killproc nfsd -2
154
	RETVAL=$?
155
	echo
156
 
157
	echo -n $"Shutting down NFS mountd: "
158
	killproc rpc.mountd
159
	rval=$?
160
	[ $RETVAL -eq 0 ] && RETVAL=$rval
161
	echo
162
	if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
163
		echo -n $"Shutting down NFS quotas: "
164
		killproc rpc.rquotad
165
		rval=$?
166
		[ $RETVAL -eq 0 ] && RETVAL=$rval
167
		echo
168
	fi
169
	# Reset the lockd ports if they were set
170
	if [ -n "$LOCKD_TCPPORT" ]; then
171
	    /sbin/sysctl -w fs.nfs.nlm_tcpport=0 >/dev/null 2>&1
172
	fi
173
	if [ -n "$LOCKD_UDPPORT" ]; then
174
	    /sbin/sysctl -w fs.nfs.nlm_udpport=0 >/dev/null 2>&1
175
	fi
176
	# Do it the last so that clients can still access the server
177
	# when the server is running.
178
	cnt=`/usr/sbin/exportfs -v | /usr/bin/wc -l`
179
	if [ $cnt -gt 0 ]; then
180
		action $"Shutting down NFS services: " /usr/sbin/exportfs -au
181
		rval=$?
182
		[ $RETVAL -eq 0 ] && RETVAL=$rval
183
	fi
184
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd stop
185
	[ -f /var/lock/subsys/nfs-rpcidmapd ] &&  /sbin/service rpcidmapd stop
186
	rm -f /var/lock/subsys/nfs
187
	rm -f /var/lock/subsys/nfs-rpcidmapd
188
	rm -f /var/lock/subsys/rpc.mountd
189
	rm -f /var/lock/subsys/rpc.rquotad
190
	;;
191
  status)
192
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd status
193
	status rpc.mountd
194
	RETVAL=$?
195
	status -l nfs nfsd
196
	rval=$?
197
	[ $RETVAL -eq 0 ] && RETVAL=$rval
198
	if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
199
		status rpc.rquotad
200
		rval=$?
201
		[ $RETVAL -eq 0 ] && RETVAL=$rval
202
	fi
203
	;;
204
  restart)
205
	$0 stop
206
	$0 start
207
	;;
208
  reload | force-reload)
209
	/usr/sbin/exportfs -r
210
	[ -f /var/lock/subsys/nfs ] && touch /var/lock/subsys/nfs
211
	;;
212
  probe)
213
	if [ ! -f /var/lock/subsys/nfs ] ; then
214
	  echo $"start"; exit 0
215
	fi
216
	/sbin/pidof rpc.mountd >/dev/null 2>&1; MOUNTD="$?"
217
	/sbin/pidof nfsd >/dev/null 2>&1; NFSD="$?"
218
	if [ $MOUNTD = 1 -o $NFSD = 1 ] ; then
219
	  echo $"restart"; exit 0
220
	fi
221
	if [ /etc/exports -nt /var/lock/subsys/nfs ] ; then
222
	  echo $"reload"; exit 0
223
	fi
224
	;;
225
  condrestart | try-restart)
226
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd condrestart
227
  	[ -f /var/lock/subsys/nfs ] && {
228
		$0 stop
229
		$0 start
230
		RETVAL=$?
231
	}
232
	;;
233
  condstop)
234
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd condstop
235
  	[ -f /var/lock/subsys/nfs ] && {
236
		$0 stop
237
		RETVAL=$?
238
	}
239
	;;
240
  *)
241
	echo $"Usage: nfs {start|stop|status|restart|reload|force-reload|condrestart|try-restart|condstop}"
242
	RETVAL=2
243
	;;
244
esac
245
 
246
exit $RETVAL