xref: /illumos-gate/usr/src/cmd/fs.d/nfs/svc/nfs-server (revision 7c478bd9)
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, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27#pragma ident	"%Z%%M%	%I%	%E% SMI"
28
29# Start/stop processes required for server NFS
30
31. /lib/svc/share/smf_include.sh
32zone=${_INIT_ZONENAME:=`/sbin/zonename`}
33
34case "$1" in
35'start')
36	# The NFS server is not supported in a local zone
37	if [ $zone != "global" ] ; then
38		/usr/sbin/svcadm disable svc:/network/nfs/server
39		echo "The NFS server is not supported in a local zone"
40		sleep 5 &
41		exit $SMF_EXIT_OK
42	fi
43
44	# If /etc/dfs/dfstab exists and has non-blank or non-commented-out
45	# lines, then run shareall to export them, and then start up mountd
46	# and nfsd if anything is exported.
47
48	startnfsd=0
49	if [ -f /etc/dfs/dfstab ] && /usr/bin/egrep -v '^[	 ]*(#|$)' \
50	    /etc/dfs/dfstab >/dev/null 2>&1; then
51
52		/usr/sbin/shareall -F nfs
53	fi
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	# Start nfslogd if /etc/nfs/nfslogtab exists and is not empty
64	# This means that either we just shared new filesystems with
65	# logging enabled, or they were shared in the previous session
66	# and their working buffers haven't been processed yet.
67
68	if [ -s /etc/nfs/nfslogtab ]; then
69		/usr/lib/nfs/nfslogd &
70	fi
71
72	# Options for nfsd are now set in /etc/default/nfs
73	if [ $startnfsd -ne 0 ]; then
74		/usr/lib/nfs/mountd
75		/usr/lib/nfs/nfsd
76	else
77		/usr/sbin/svcadm disable svc:/network/nfs/server
78		echo "No NFS filesystems are shared"
79		sleep 5 &
80	fi
81
82	;;
83
84'stop')
85	/usr/bin/pkill -x -u 0,1 -z $zone '(nfsd|mountd)'
86
87	if /usr/bin/grep -s nfs /etc/dfs/sharetab >/dev/null; then
88		/usr/sbin/unshareall -F nfs
89	fi
90
91	#
92	# Wait up to 10 seconds for nfslogd to gracefully handle SIGHUP
93	#
94	/usr/bin/pkill -HUP -x -u 0 -z $zone nfslogd
95	wtime=10
96
97	while [ $wtime -gt 0 ]; do
98		/usr/bin/pgrep -x -u 0 -z $zone nfslogd >/dev/null || break
99		wtime=`expr $wtime - 1`
100		sleep 1
101	done
102
103	#
104	# Kill nfslogd more forcefully if it did not shutdown during
105	# the grace period
106	#
107	if [ $wtime -eq 0 ]; then
108		/usr/bin/pkill -TERM -x -u 0 -z $zone nfslogd
109	fi
110
111	# Kill any processes left in service contract
112	smf_kill_contract $2 TERM 1
113	[ $? -ne 0 ] && exit 1
114	;;
115*)
116	echo "Usage: $0 { start | stop }"
117	exit 1
118	;;
119esac
120exit $SMF_EXIT_OK
121