xref: /illumos-gate/usr/src/cmd/fs.d/nfs/svc/nfs-server (revision 3fd3a04a9f762fea5da9e64d29593959c18f74a2)
17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
67c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
77c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
87c478bd9Sstevel@tonic-gate# with the License.
97c478bd9Sstevel@tonic-gate#
107c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
117c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
127c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
137c478bd9Sstevel@tonic-gate# and limitations under the License.
147c478bd9Sstevel@tonic-gate#
157c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
167c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
177c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
187c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
197c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
207c478bd9Sstevel@tonic-gate#
217c478bd9Sstevel@tonic-gate# CDDL HEADER END
227c478bd9Sstevel@tonic-gate#
237c478bd9Sstevel@tonic-gate#
247c478bd9Sstevel@tonic-gate# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate# Start/stop processes required for server NFS
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate. /lib/svc/share/smf_include.sh
327c478bd9Sstevel@tonic-gatezone=${_INIT_ZONENAME:=`/sbin/zonename`}
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gatecase "$1" in
357c478bd9Sstevel@tonic-gate'start')
367c478bd9Sstevel@tonic-gate	# The NFS server is not supported in a local zone
377c478bd9Sstevel@tonic-gate	if [ $zone != "global" ] ; then
38*3fd3a04aSthurlow		/usr/sbin/svcadm disable -t svc:/network/nfs/server
397c478bd9Sstevel@tonic-gate		echo "The NFS server is not supported in a local zone"
407c478bd9Sstevel@tonic-gate		sleep 5 &
417c478bd9Sstevel@tonic-gate		exit $SMF_EXIT_OK
427c478bd9Sstevel@tonic-gate	fi
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate	# If /etc/dfs/dfstab exists and has non-blank or non-commented-out
457c478bd9Sstevel@tonic-gate	# lines, then run shareall to export them, and then start up mountd
467c478bd9Sstevel@tonic-gate	# and nfsd if anything is exported.
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate	startnfsd=0
497c478bd9Sstevel@tonic-gate	if [ -f /etc/dfs/dfstab ] && /usr/bin/egrep -v '^[	 ]*(#|$)' \
507c478bd9Sstevel@tonic-gate	    /etc/dfs/dfstab >/dev/null 2>&1; then
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate		/usr/sbin/shareall -F nfs
537c478bd9Sstevel@tonic-gate	fi
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate	if /usr/bin/grep -s nfs /etc/dfs/sharetab >/dev/null; then
567c478bd9Sstevel@tonic-gate		startnfsd=1
577c478bd9Sstevel@tonic-gate	fi
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate	# When the system comes up umask is not set; so set the mode now
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate	[ -f /etc/dfs/sharetab ] && /usr/bin/chmod 644 /etc/dfs/sharetab
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate	# Start nfslogd if /etc/nfs/nfslogtab exists and is not empty
647c478bd9Sstevel@tonic-gate	# This means that either we just shared new filesystems with
657c478bd9Sstevel@tonic-gate	# logging enabled, or they were shared in the previous session
667c478bd9Sstevel@tonic-gate	# and their working buffers haven't been processed yet.
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate	if [ -s /etc/nfs/nfslogtab ]; then
697c478bd9Sstevel@tonic-gate		/usr/lib/nfs/nfslogd &
707c478bd9Sstevel@tonic-gate	fi
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate	# Options for nfsd are now set in /etc/default/nfs
737c478bd9Sstevel@tonic-gate	if [ $startnfsd -ne 0 ]; then
747c478bd9Sstevel@tonic-gate		/usr/lib/nfs/mountd
757c478bd9Sstevel@tonic-gate		/usr/lib/nfs/nfsd
767c478bd9Sstevel@tonic-gate	else
77*3fd3a04aSthurlow		/usr/sbin/svcadm disable -t svc:/network/nfs/server
787c478bd9Sstevel@tonic-gate		echo "No NFS filesystems are shared"
797c478bd9Sstevel@tonic-gate		sleep 5 &
807c478bd9Sstevel@tonic-gate	fi
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate	;;
837c478bd9Sstevel@tonic-gate
84*3fd3a04aSthurlow'refresh')
85*3fd3a04aSthurlow	/usr/sbin/shareall -F nfs
86*3fd3a04aSthurlow	;;
87*3fd3a04aSthurlow
887c478bd9Sstevel@tonic-gate'stop')
897c478bd9Sstevel@tonic-gate	/usr/bin/pkill -x -u 0,1 -z $zone '(nfsd|mountd)'
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate	if /usr/bin/grep -s nfs /etc/dfs/sharetab >/dev/null; then
927c478bd9Sstevel@tonic-gate		/usr/sbin/unshareall -F nfs
937c478bd9Sstevel@tonic-gate	fi
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate	#
967c478bd9Sstevel@tonic-gate	# Wait up to 10 seconds for nfslogd to gracefully handle SIGHUP
977c478bd9Sstevel@tonic-gate	#
987c478bd9Sstevel@tonic-gate	/usr/bin/pkill -HUP -x -u 0 -z $zone nfslogd
997c478bd9Sstevel@tonic-gate	wtime=10
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate	while [ $wtime -gt 0 ]; do
1027c478bd9Sstevel@tonic-gate		/usr/bin/pgrep -x -u 0 -z $zone nfslogd >/dev/null || break
1037c478bd9Sstevel@tonic-gate		wtime=`expr $wtime - 1`
1047c478bd9Sstevel@tonic-gate		sleep 1
1057c478bd9Sstevel@tonic-gate	done
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate	#
1087c478bd9Sstevel@tonic-gate	# Kill nfslogd more forcefully if it did not shutdown during
1097c478bd9Sstevel@tonic-gate	# the grace period
1107c478bd9Sstevel@tonic-gate	#
1117c478bd9Sstevel@tonic-gate	if [ $wtime -eq 0 ]; then
1127c478bd9Sstevel@tonic-gate		/usr/bin/pkill -TERM -x -u 0 -z $zone nfslogd
1137c478bd9Sstevel@tonic-gate	fi
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate	# Kill any processes left in service contract
1167c478bd9Sstevel@tonic-gate	smf_kill_contract $2 TERM 1
1177c478bd9Sstevel@tonic-gate	[ $? -ne 0 ] && exit 1
1187c478bd9Sstevel@tonic-gate	;;
119*3fd3a04aSthurlow
1207c478bd9Sstevel@tonic-gate*)
121*3fd3a04aSthurlow	echo "Usage: $0 { start | stop | refresh }"
1227c478bd9Sstevel@tonic-gate	exit 1
1237c478bd9Sstevel@tonic-gate	;;
1247c478bd9Sstevel@tonic-gateesac
1257c478bd9Sstevel@tonic-gateexit $SMF_EXIT_OK
126