xref: /illumos-gate/usr/src/cmd/fs.d/nfs/svc/nfs-server (revision d5dbd18d69de8954ab5ceb588e99d43fc9b21d46)
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 -t 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 -t svc:/network/nfs/server
78		echo "No NFS filesystems are shared"
79		sleep 5 &
80	fi
81
82	;;
83
84'refresh')
85	/usr/sbin/shareall -F nfs
86	;;
87
88'stop')
89	/usr/bin/pkill -x -u 0,1 -z $zone '(nfsd|mountd)'
90
91	if /usr/bin/grep -s nfs /etc/dfs/sharetab >/dev/null; then
92		/usr/sbin/unshareall -F nfs
93	fi
94
95	#
96	# Wait up to 10 seconds for nfslogd to gracefully handle SIGHUP
97	#
98	/usr/bin/pkill -HUP -x -u 0 -z $zone nfslogd
99	wtime=10
100
101	while [ $wtime -gt 0 ]; do
102		/usr/bin/pgrep -x -u 0 -z $zone nfslogd >/dev/null || break
103		wtime=`expr $wtime - 1`
104		sleep 1
105	done
106
107	#
108	# Kill nfslogd more forcefully if it did not shutdown during
109	# the grace period
110	#
111	if [ $wtime -eq 0 ]; then
112		/usr/bin/pkill -TERM -x -u 0 -z $zone nfslogd
113	fi
114
115	# Kill any processes left in service contract
116	smf_kill_contract $2 TERM 1
117	[ $? -ne 0 ] && exit 1
118	;;
119
120*)
121	echo "Usage: $0 { start | stop | refresh }"
122	exit 1
123	;;
124esac
125exit $SMF_EXIT_OK
126