#!/bin/sh # # nfs This shell script takes care of starting and stopping # the NFS services. # # chkconfig: 345 60 20 # description: NFS is a popular protocol for file sharing across TCP/IP \ # networks. This service provides NFS server functionality, \ # which is configured via the /etc/exports file. # ### BEGIN INIT INFO # Provides: nfs # Required-Start: $network $portmap # Required-Stop: $network $portmap # Default-Start: 3 4 5 # Short-Description: NFS services # Description: NFS is a popular protocol for file sharing across TCP/IP # networks. This service provides NFS server functionality, # which is configured via the /etc/exports file. ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "${NETWORKING}" = "no" ] && exit 0 # fail if /etc/exports doesn't exist if [ ! -f /etc/exports ]; then echo "/etc/exports does not exist" exit 1 fi # Set defaults and read configuration LOCKFILE=/var/lock/subsys/nfs MOUNTD_NFS_V2=default MOUNTD_NFS_V3=default RPCNFSDCOUNT=8 RQUOTAD=`type -path rpc.rquotad` [ -f /etc/sysconfig/nfs ] && . /etc/sysconfig/nfs start() { if [ ! -f $LOCKFILE ]; then /sbin/service portmap start # Start daemons. action "Starting NFS services: " /usr/sbin/exportfs -r # Set the ports lockd should listen on if [ -n "$LOCKD_TCPPORT" ]; then /sbin/sysctl -w fs.nfs.nlm_tcpport=$LOCKD_TCPPORT >/dev/null 2>&1 fi if [ -n "$LOCKD_UDPPORT" ]; then /sbin/sysctl -w fs.nfs.nlm_udpport=$LOCKD_UDPPORT >/dev/null 2>&1 fi if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then echo -n "Starting NFS quotas: " [ -n "$RQUOTAD_PORT" ] \ && RPCRQUOTADOPTS="$RPCRQUOTADOPTS -p $RQUOTAD_PORT" daemon rpc.rquotad $RPCRQUOTADOPTS echo fi [ -n "$MOUNTD_PORT" ] \ && RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT" case $MOUNTD_NFS_V2 in no|NO) RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 2" ;; esac case $MOUNTD_NFS_V3 in no|NO) RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3" ;; esac echo -n "Starting NFS mountd: " daemon rpc.mountd $RPCMOUNTDOPTS echo if [ "$USE_NFS4" = yes ]; then /sbin/service rpcidmapd start if [ "$SECURE_NFS" = yes ]; then /sbin/service rpcsvcgssd start fi fi echo -n "Starting NFS daemon: " daemon rpc.nfsd $RPCNFSDCOUNT echo touch $LOCKFILE fi return 0 } stop() { if [ "$USE_NFS4" = yes ]; then /sbin/service rpcidmapd stop if [ "$SECURE_NFS" = yes ]; then /sbin/service rpcsvcgssd stop fi fi echo -n "Shutting down NFS mountd: " killproc rpc.mountd echo echo -n "Shutting down NFS daemon: " killproc nfsd echo if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then echo -n "Shutting down NFS quotas: " killproc rpc.rquotad echo fi # Reset the lockd ports if they were set if [ -n "$LOCKD_TCPPORT" ]; then /sbin/sysctl -w fs.nfs.nlm_tcpport=0 >/dev/null 2>&1 fi if [ -n "$LOCKD_UDPPORT" ]; then /sbin/sysctl -w fs.nfs.nlm_udpport=0 >/dev/null 2>&1 fi # Do it the last so that clients can still access the server # when the server is running. action "Shutting down NFS services: " /usr/sbin/exportfs -au rm -f $LOCKFILE return 0 } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) if [ "$USE_NFS4" = yes ]; then /sbin/service rpcidmapd status if [ "$SECURE_NFS" = yes ]; then /sbin/service rpcsvcgssd status fi fi status rpc.mountd if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then status rpc.rquotad fi status nfsd ;; restart) stop start ;; reload) /usr/sbin/exportfs -r touch $LOCKFILE ;; probe) if [ ! -f $LOCKFILE ]; then echo "start" exit 0 fi /sbin/pidof rpc.mountd >/dev/null 2>&1; MOUNTD="$?" /sbin/pidof nfsd >/dev/null 2>&1; NFSD="$?" if [ $MOUNTD = 1 -o $NFSD = 1 ]; then echo "restart" exit 0 fi if [ /etc/exports -nt $LOCKFILE ]; then echo "reload" exit 0 fi ;; condrestart) [ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd condrestart if [ -f $LOCKFILE ]; then stop start fi ;; *) echo "Usage: nfs {start|stop|status|restart|reload|probe|condrestart}" exit 1 ;; esac exit $?