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