#!/bin/sh # $Id: nfs-server.init 228079 2008-06-23 13:59:47Z guillomovitch $ # chkconfig: 345 60 20 # description: Kernel NFS server support ### BEGIN INIT INFO # Provides: nfs-server # Required-Start: nfs-common $named # Required-Stop: nfs-common $named # Default-Start: 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Kernel NFS server support # 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 # Read config NAME="NFS kernel daemon" LOCKFILE=/var/lock/subsys/nfs-server PROCNFSD_MOUNTPOINT=/proc/fs/nfsd RPCNFSDCOUNT=8 RPCMOUNTD_OPTIONS= NEED_SVCGSSD=no RPCSVCGSSD_OPTIONS= NEED_QUOTAD= RPCRQUOTAD_OPTIONS= [ -f /etc/sysconfig/nfs-server ] && . /etc/sysconfig/nfs-server # Parse the fstab file, and determine whether we need quotad if grep -q '^[^#]*quota' /etc/fstab; then AUTO_NEED_QUOTAD=yes else AUTO_NEED_QUOTAD=no fi case "$NEED_QUOTAD" in yes|no) ;; *) NEED_QUOTAD=$AUTO_NEED_QUOTAD ;; esac do_modprobe() { if [ -x /sbin/modprobe -a -f /proc/modules ]; then modprobe -q "$1" || true fi } do_mount() { if ! grep -E -qs "$1\$" /proc/filesystems; then return 1 fi if ! mountpoint -q "$2"; then mount -t "$1" "$1" "$2" return fi return 0 } start() { if [ ! -f $LOCKFILE ]; then do_modprobe nfsd # See if our running kernel supports the NFS kernel server if [ -f /proc/kallsyms ] && ! grep -qE 'init_nf(sd| )' /proc/kallsyms; then echo "Not starting $NAME: no support in current kernel." return 0 fi if ! do_mount nfsd $PROCNFSD_MOUNTPOINT; then NEED_SVCGSSD=no fi echo -n "Exporting directories for $NAME..." exportfs -r rc=$? echo if [ $rc != 0 ]; then return $rc fi echo "Starting $NAME" echo -n "Starting nfsd" daemon rpc.nfsd $RPCNFSD_OPTIONS $RPCNFSDCOUNT rc=$? echo if [ $rc != 0 ]; then return $rc fi if [ "$NEED_SVCGSSD" = "yes" ]; then echo -n "Starting rpc.svcgssd" daemon rpc.svcgssd $RPCSVCGSSD_OPTIONS rc=$? echo if [ $rc != 0 ]; then return $rc fi fi if [ "$NEED_QUOTAD" = "yes" -a -x /usr/sbin/rpc.rquotad ]; then echo -n "Starting rpc.rquotad" daemon rpc.rquotad $RPCRQUOTAD_OPTIONS rc=$? echo if [ $rc != 0 ]; then return $rc fi fi if pidof rpc.idmapd; then killproc rpc.idmapd -SIGHUP fi echo -n "Starting rpc.mountd" daemon rpc.mountd $RPCMOUNTD_OPTIONS rc=$? echo if [ $rc != 0 ]; then return $rc fi touch $LOCKFILE fi return 0 } stop() { echo "Stopping $NAME" echo -n "Stopping rpc.mountd:" killproc rpc.mountd rc=$? echo if [ $rc != 0 ]; then return $rc fi if [ "$NEED_SVCGSSD" = "yes" ]; then echo -n "Stopping rpc.svcgssd:" killproc rpc.svcgssd rc=$? echo if [ $rc != 0 ]; then return $rc fi fi if [ "$NEED_QUOTAD" = "yes" -a -x /usr/sbin/rpc.rquotad ]; then echo -n "Stopping rpc.rquotad:" killproc rpc.rquotad rc=$? echo if [ $rc != 0 ]; then return $rc fi fi echo -n "Stopping nfsd:" killproc nfsd rc=$? echo if [ $rc != 0 ]; then return $rc fi echo -n "Unexporting directories for $NAME..." exportfs -au rc=$? echo if [ $rc != 0 ]; then return $rc fi if mountpoint -q /proc/nfs/nfsd; then exportfs -f fi rm -f $LOCKFILE return 0 } reload() { echo -n "Re-exporting directories for $NAME..." exportfs -r rc=$? echo return $rc } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status nfsd status rpc.mountd if [ "$NEED_QUOTAD" = "yes" -a -x /usr/sbin/rpc.rquotad ]; then status rpc.rquotad fi if [ "$NEED_SVCGSSD" = yes ]; then status rpc.svcgssd fi ;; reload) reload ;; restart) stop sleep 1 start ;; *) echo "Usage: $0 {start|stop|restart|reload|status}" exit 1 ;; esac exit 0