comparison usr/src/cmd/fs.d/nfs/svc/nfs-server @ 0:c9caec207d52 b86

Initial porting based on b86
author Koji Uno <koji.uno@sun.com>
date Tue, 02 Jun 2009 18:56:50 +0900
parents
children 1a15d5aaf794
comparison
equal deleted inserted replaced
-1:000000000000 0:c9caec207d52
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 "@(#)nfs-server 1.15 07/04/02 SMI"
27
28 # Start/stop processes required for server NFS
29
30 . /lib/svc/share/smf_include.sh
31 zone=`smf_zonename`
32
33 case "$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 # Options for nfsd are now set in /etc/default/nfs
66 if [ $startnfsd -ne 0 ]; then
67 /usr/lib/nfs/mountd
68 /usr/lib/nfs/nfsd
69 else
70 /usr/sbin/svcadm disable -t svc:/network/nfs/server
71 echo "No NFS filesystems are shared"
72 sleep 5 &
73 fi
74
75 ;;
76
77 'refresh')
78 /usr/sbin/sharemgr start -P nfs -a
79 ;;
80
81 'stop')
82 /usr/bin/pkill -x -u 0,1 -z $zone '(nfsd|mountd)'
83
84 # Unshare all shared file systems using NFS
85
86 /usr/sbin/sharemgr stop -P nfs -a
87
88 #
89 # Wait up to 10 seconds for nfslogd to gracefully handle SIGHUP
90 #
91 /usr/bin/pkill -HUP -x -u 0 -z $zone nfslogd
92 wtime=10
93
94 while [ $wtime -gt 0 ]; do
95 /usr/bin/pgrep -x -u 0 -z $zone nfslogd >/dev/null || break
96 wtime=`expr $wtime - 1`
97 sleep 1
98 done
99
100 #
101 # Kill nfslogd more forcefully if it did not shutdown during
102 # the grace period
103 #
104 if [ $wtime -eq 0 ]; then
105 /usr/bin/pkill -TERM -x -u 0 -z $zone nfslogd
106 fi
107
108 # Kill any processes left in service contract
109 smf_kill_contract $2 TERM 1
110 [ $? -ne 0 ] && exit 1
111 ;;
112
113 *)
114 echo "Usage: $0 { start | stop | refresh }"
115 exit 1
116 ;;
117 esac
118 exit $SMF_EXIT_OK