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