#!/bin/sh # # nfs This shell script takes care of starting and stopping # the 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. # Source functions library source /etc/rc.d/init.d/functions log_script_name "$0 $*" # Load global network parameters source /etc/sysconfig/network/network-parameters # Check that networking is up. #[ ${NETWORKING} = "no" ] && exit ${EXIT_CODE_WARNING} # Check if NFS server functionality is desired if [ "x${NFS_SERVER_ENA}" != "xyes" -a "x${NFS_SERVER_ENA}" != "xYes" -a "x${NFS_SERVER_ENA}" != "xYES" ]; then exit ${EXIT_CODE_SUCCESS} fi # Check for presence of executables if [ ! -x /sbin/rpc.nfsd ]; then echo "Missing rpc.nfsd executable" exit ${EXIT_CODE_WARNING} fi if [ ! -x /sbin/rpc.mountd ]; then echo "Missing rpc.mountd executable" exit ${EXIT_CODE_WARNING} fi if [ ! -x /sbin/exportfs ]; then echo "Missing exportfs executable" exit ${EXIT_CODE_WARNING} fi if [ ! -s /etc/exports ]; then echo "Missing /etc/exports configuration file" exit ${EXIT_CODE_WARNING} fi # Check for and source configuration file otherwise set defaults # TUNE_QUEUE: controls whether to up the size of input queues [ -f /etc/sysconfig/network/nfs ] && . /etc/sysconfig/network/nfs [ -z "$MOUNTD_NFS_V2" ] && MOUNTD_NFS_V2=auto [ -z "$MOUNTD_NFS_V3" ] && MOUNTD_NFS_V3=auto # Number of servers to be started by default [ -z "$NFSDCOUNT" ] && NFSDCOUNT=8 # Remote quota server [ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad` # Get the initial values for the input sock queues # at the time of running the script. if [ "$TUNE_QUEUE" = "yes" ]; then RMEM_DEFAULT=`/sbin/sysctl -n net.core.rmem_default` RMEM_MAX=`/sbin/sysctl -n net.core.rmem_max` # 256kb recommended minimum size based on SPECsfs NFS benchmarks [ -z "$NFS_QS" ] && NFS_QS=262144 fi MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-nfs-version 2" MOUNTD_OPTIONS="$MOUNTD_OPTIONS --nfs-version 3" nfsd_start() { # Apply input queue increase for nfs server if [ "$TUNE_QUEUE" = "yes" ]; then /sbin/sysctl -w net.core.rmem_default=$NFSD_QS >/dev/null 2>&1 /sbin/sysctl -w net.core.rmem_max=$NFSD_QS >/dev/null 2>&1 fi cmd_run_log_box "Starting NFS services" loadproc /sbin/exportfs -ra if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then cmd_run_log_box "Starting NFS quotas" loadproc rpc.rquotad fi cmd_run_log_box "Starting NFS daemon" loadproc rpc.nfsd $NFSDCOUNT [ -n "$MOUNTD_PORT" ] \ && MOUNTD_OPTIONS="$MOUNTD_OPTIONS -p $MOUNTD_PORT" [ "$MOUNTD_TCP" = "no" -o "$MOUNTD_TCP" = "NO" ] \ && MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-tcp" cmd_run_log_box "Starting NFS mountd" loadproc rpc.mountd $MOUNTD_OPTIONS touch /var/lock/subsys/nfs # reset input queue for rest of network services if [ "$TUNE_QUEUE" = "yes" ]; then /sbin/sysctl -w net.core.rmem_default=$RMEM_DEFAULT >/dev/null 2>&1 /sbin/sysctl -w net.core.rmem_max=$RMEM_MAX >/dev/null 2>&1 fi } nfsd_stop() { cmd_run_log_box "Stopping NFS mountd" killproc rpc.mountd cmd_run_log_box "Stopping NFS daemon" killproc nfsd if [ -n "$RQUOTAD" ]; then cmd_run_log_box "Stopping NFS quotas" killproc rpc.rquotad fi # Do it the last so that clients can still access the server # when the server is running. echo "Refreshing NFS Exported Filesystems..." /sbin/exportfs -au rm -f /var/lock/subsys/nfs } # See how we were called case "$1" in start) cmd_run_log_box_warn "NFS server start" nfsd_start ;; stop) cmd_run_log_box_warn "NFS server stop" nfsd_stop ;; reload) /sbin/exportfs -ra touch /var/lock/subsys/nfs ;; restart) $0 stop sleep 1 $0 start ;; status) statusproc rpc.mountd statusproc nfsd if [ -n "$RQUOTAD" ]; then statusproc rpc.rquotad fi ;; *) echo "Usage: $0 {reload|restart|start|status|stop}" exit ${EXIT_CODE_FAILURE} ;; esac exit $?