xref: /titanic_50/usr/src/cmd/fs.d/nfs/svc/nfs-server (revision 549ec3fff108310966327d1dc9004551b63210b7)
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 2007 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	# When the system comes up umask is not set; so set the mode now
66
67	[ -f /etc/dfs/sharetab ] && /usr/bin/chmod 644 /etc/dfs/sharetab
68
69	# Options for nfsd are now set in /etc/default/nfs
70	if [ $startnfsd -ne 0 ]; then
71		/usr/lib/nfs/mountd
72		/usr/lib/nfs/nfsd
73	else
74		/usr/sbin/svcadm disable -t svc:/network/nfs/server
75		echo "No NFS filesystems are shared"
76		sleep 5 &
77	fi
78
79	;;
80
81'refresh')
82	/usr/sbin/sharemgr start -P nfs -a
83	;;
84
85'stop')
86	/usr/bin/pkill -x -u 0,1 -z $zone '(nfsd|mountd)'
87
88	# Unshare all shared file systems using NFS
89
90	/usr/sbin/sharemgr stop -P nfs -a
91
92	#
93	# Wait up to 10 seconds for nfslogd to gracefully handle SIGHUP
94	#
95	/usr/bin/pkill -HUP -x -u 0 -z $zone nfslogd
96	wtime=10
97
98	while [ $wtime -gt 0 ]; do
99		/usr/bin/pgrep -x -u 0 -z $zone nfslogd >/dev/null || break
100		wtime=`expr $wtime - 1`
101		sleep 1
102	done
103
104	#
105	# Kill nfslogd more forcefully if it did not shutdown during
106	# the grace period
107	#
108	if [ $wtime -eq 0 ]; then
109		/usr/bin/pkill -TERM -x -u 0 -z $zone nfslogd
110	fi
111
112	# Kill any processes left in service contract
113	smf_kill_contract $2 TERM 1
114	[ $? -ne 0 ] && exit 1
115	;;
116
117*)
118	echo "Usage: $0 { start | stop | refresh }"
119	exit 1
120	;;
121esac
122exit $SMF_EXIT_OK
123