PageRenderTime 100ms CodeModel.GetById 91ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/rc3.d/S20nfs-kernel-server

http://github.com/brinkman83/bashrc
Shell | 215 lines | 167 code | 29 blank | 19 comment | 38 complexity | 68d22ac7f9e2d0c75e7a8fc143fa3a0a MD5 | raw file
  1#!/bin/sh
  2
  3### BEGIN INIT INFO
  4# Provides:          nfs-kernel-server
  5# Required-Start:    $remote_fs nfs-common $portmap $time
  6# Required-Stop:     $remote_fs nfs-common $portmap $time
  7# Default-Start:     2 3 4 5
  8# Default-Stop:      0 1 6
  9# Short-Description: Kernel NFS server support
 10# Description:       NFS is a popular protocol for file sharing across
 11#		     TCP/IP networks. This service provides NFS server
 12#                    functionality, which is configured via the
 13#                    /etc/exports file.
 14### END INIT INFO
 15
 16# What is this?
 17DESC="NFS kernel daemon"
 18PREFIX=/usr
 19
 20# Exit if required binaries are missing.
 21[ -x $PREFIX/sbin/rpc.nfsd    ] || exit 0
 22[ -x $PREFIX/sbin/rpc.mountd  ] || exit 0
 23[ -x $PREFIX/sbin/exportfs    ] || exit 0
 24
 25# Read config
 26DEFAULTFILE=/etc/default/nfs-kernel-server
 27RPCNFSDCOUNT=8
 28RPCNFSDPRIORITY=0
 29RPCMOUNTDOPTS=
 30NEED_SVCGSSD=no
 31RPCSVCGSSDOPTS=
 32PROCNFSD_MOUNTPOINT=/proc/fs/nfsd
 33if [ -f $DEFAULTFILE ]; then
 34    . $DEFAULTFILE
 35fi
 36
 37. /lib/lsb/init-functions
 38
 39do_modprobe() {
 40    if [ -x /sbin/modprobe -a -f /proc/modules ]
 41    then
 42        modprobe -q "$1" || true
 43    fi
 44}
 45
 46do_mount() {
 47    if ! grep -E -qs "$1\$" /proc/filesystems
 48    then
 49	return 1
 50    fi
 51    if ! mountpoint -q "$2"
 52    then
 53	mount -t "$1" "$1" "$2"
 54	return
 55    fi
 56    return 0
 57}
 58
 59# See how we were called.
 60case "$1" in
 61  start)
 62	if [ -f /etc/exports ]
 63	then
 64		do_modprobe nfsd
 65
 66		# See if our running kernel supports the NFS kernel server
 67		if [ -f /proc/kallsyms ] && ! grep -qE ' nfsd_serv	' /proc/kallsyms; then
 68			log_warning_msg "Not starting $DESC: no support in current kernel."
 69			exit 0
 70		fi
 71		
 72		do_mount nfsd $PROCNFSD_MOUNTPOINT || NEED_SVCGSSD=no
 73		log_begin_msg "Exporting directories for $DESC..."
 74		$PREFIX/sbin/exportfs -r
 75		RET=$?
 76		if [ $RET != 0 ]; then
 77			log_end_msg $RET
 78			exit $RET
 79		fi
 80		log_end_msg 0
 81
 82		log_daemon_msg "Starting $DESC"
 83		log_progress_msg "nfsd"
 84		start-stop-daemon --start --oknodo --quiet \
 85		    --nicelevel $RPCNFSDPRIORITY \
 86		    --exec $PREFIX/sbin/rpc.nfsd -- $RPCNFSDCOUNT
 87		RET=$?
 88		if [ $RET != 0 ]; then
 89			log_end_msg $RET
 90			exit $RET
 91		fi
 92
 93		# make sure 127.0.0.1 is a valid source for requests
 94		ClearAddr=
 95		if [ -f /proc/net/rpc/auth.unix.ip/channel ]
 96		then
 97		    fgrep -qs 127.0.0.1 /proc/net/rpc/auth.unix.ip/content || {
 98			echo "nfsd 127.0.0.1 2147483647 localhost" >/proc/net/rpc/auth.unix.ip/channel
 99			ClearAddr=yes
100		    }
101		fi
102
103		$PREFIX/bin/rpcinfo -u localhost nfs 3 >/dev/null 2>&1 ||
104		    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3"
105
106		[ -z "$ClearAddr" ] || echo "nfsd 127.0.0.1 1" >/proc/net/rpc/auth.unix.ip/channel
107	
108	        if [ "$NEED_SVCGSSD" = "yes" ]; then
109			do_modprobe rpcsec_gss_krb5
110			log_progress_msg "svcgssd"
111			start-stop-daemon --start --oknodo --quiet \
112			    --exec $PREFIX/sbin/rpc.svcgssd -- $RPCSVCGSSDOPTS
113			RET=$?
114			if [ $RET != 0 ]; then
115				log_end_msg $RET
116				exit $RET
117			fi
118		fi
119
120		log_progress_msg "mountd"
121		start-stop-daemon --start --oknodo --quiet \
122		    --exec $PREFIX/sbin/rpc.mountd -- $RPCMOUNTDOPTS
123		RET=$?
124		if [ $RET != 0 ]; then
125			log_end_msg $RET
126			exit $RET
127		fi
128
129		log_end_msg 0
130	else
131		log_warning_msg "Not starting $DESC: no exports."
132	fi
133	;;
134
135  stop)
136	log_daemon_msg "Stopping $DESC"
137
138	log_progress_msg "mountd"
139	start-stop-daemon --stop --oknodo --quiet \
140	    --name rpc.mountd --user 0
141	RET=$?
142	if [ $RET != 0 ]; then
143		log_end_msg $RET
144		exit $RET
145	fi
146
147	if [ "$NEED_SVCGSSD" = "yes" ]; then
148		log_progress_msg "svcgssd"
149		start-stop-daemon --stop --oknodo --quiet \
150		    --name rpc.svcgssd --user 0
151		RET=$?
152		if [ $RET != 0 ]; then
153			log_end_msg $RET
154			exit $RET
155		fi
156	fi
157
158	log_progress_msg "nfsd"
159	start-stop-daemon --stop --oknodo --quiet \
160	    --name nfsd --user 0 --signal 2
161	RET=$?
162	if [ $RET != 0 ]; then
163		log_end_msg $RET
164		exit $RET
165	fi
166
167	log_end_msg 0
168
169	log_begin_msg "Unexporting directories for $DESC..."
170	$PREFIX/sbin/exportfs -au
171	RET=$?
172	if [ $RET != 0 ]; then
173		log_end_msg $RET
174		exit $RET
175	fi
176	log_end_msg 0
177
178	if mountpoint -q $PROCNFSD_MOUNTPOINT
179	then
180	    $PREFIX/sbin/exportfs -f
181	fi
182	;;
183
184  status)
185	if pidof nfsd >/dev/null
186	then
187	    echo "nfsd running"
188	    exit 0
189	else
190	    echo "nfsd not running"
191	    exit 3
192	fi
193	;;
194
195  reload | force-reload)
196	log_begin_msg "Re-exporting directories for $DESC..."
197	$PREFIX/sbin/exportfs -r
198	RET=$?
199	log_end_msg $RET
200	exit $RET
201	;;
202
203  restart)
204	$0 stop
205	sleep 1
206	$0 start
207	;;
208
209  *)
210	log_success_msg "Usage: nfs-kernel-server {start|stop|status|reload|force-reload|restart}"
211	exit 1
212	;;
213esac
214
215exit 0