xref: /titanic_51/usr/src/cmd/fs.d/nfs/svc/nfs-server (revision b87f3af36bb994656da117319f5129ddfd05ed21)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26#pragma ident	"%Z%%M%	%I%	%E% SMI"
27
28# Start/stop processes required for server NFS
29
30. /lib/svc/share/smf_include.sh
31zone=`smf_zonename`
32
33case "$1" in
34'start')
35	# The NFS server is not supported in a local zone
36	if smf_is_nonglobalzone; then
37		/usr/sbin/svcadm disable -t svc:/network/nfs/server
38		echo "The NFS server is not supported in a local zone"
39		sleep 5 &
40		exit $SMF_EXIT_OK
41	fi
42
43	# Share all file systems enabled for sharing. sharemgr understands
44	# regular shares and ZFS shares and will handle both. Technically,
45	# the shares would have been started long before getting here since
46	# nfsd has a dependency on them.
47
48	startnfsd=0
49
50	# restart stopped shares from the repository
51	/usr/sbin/sharemgr start -P nfs -a
52
53	# Start up mountd and nfsd if anything is exported.
54
55	if /usr/bin/grep -s nfs /etc/dfs/sharetab >/dev/null; then
56		startnfsd=1
57	fi
58
59	# If auto-enable behavior is disabled, always start nfsd
60
61	if [ `svcprop -p application/auto_enable nfs/server` = "false" ]; then
62		startnfsd=1
63	fi
64
65	# Options for nfsd are now set in /etc/default/nfs
66	if [ $startnfsd -ne 0 ]; then
67		/usr/lib/nfs/mountd
68		rc=$?
69		if [ $rc != 0 ]; then
70			/usr/sbin/svcadm mark -t maintenance svc:/network/nfs/server
71			echo "$0: mountd failed with $rc"
72			sleep 5 &
73			exit $SMF_EXIT_ERR_FATAL
74		fi
75
76		/usr/lib/nfs/nfsd
77		rc=$?
78		if [ $rc != 0 ]; then
79			/usr/sbin/svcadm mark -t maintenance svc:/network/nfs/server
80			echo "$0: nfsd failed with $rc"
81			sleep 5 &
82			exit $SMF_EXIT_ERR_FATAL
83		fi
84	else
85		/usr/sbin/svcadm disable -t svc:/network/nfs/server
86		echo "No NFS filesystems are shared"
87		sleep 5 &
88	fi
89
90	;;
91
92'refresh')
93	/usr/sbin/sharemgr start -P nfs -a
94	;;
95
96'stop')
97	/usr/bin/pkill -x -u 0,1 -z $zone '(nfsd|mountd)'
98
99	# Unshare all shared file systems using NFS
100
101	/usr/sbin/sharemgr stop -P nfs -a
102
103	#
104	# Wait up to 10 seconds for nfslogd to gracefully handle SIGHUP
105	#
106	/usr/bin/pkill -HUP -x -u 0 -z $zone nfslogd
107	wtime=10
108
109	while [ $wtime -gt 0 ]; do
110		/usr/bin/pgrep -x -u 0 -z $zone nfslogd >/dev/null || break
111		wtime=`expr $wtime - 1`
112		sleep 1
113	done
114
115	#
116	# Kill nfslogd more forcefully if it did not shutdown during
117	# the grace period
118	#
119	if [ $wtime -eq 0 ]; then
120		/usr/bin/pkill -TERM -x -u 0 -z $zone nfslogd
121	fi
122
123	# Kill any processes left in service contract
124	smf_kill_contract $2 TERM 1
125	[ $? -ne 0 ] && exit 1
126	;;
127
128*)
129	echo "Usage: $0 { start | stop | refresh }"
130	exit 1
131	;;
132esac
133exit $SMF_EXIT_OK
134