17c478bd9Sstevel@tonic-gate#!/sbin/sh 27c478bd9Sstevel@tonic-gate# 37c478bd9Sstevel@tonic-gate# CDDL HEADER START 47c478bd9Sstevel@tonic-gate# 57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 66927f468Sdp# Common Development and Distribution License (the "License"). 76927f468Sdp# You may not use this file except in compliance with the License. 87c478bd9Sstevel@tonic-gate# 97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate# and limitations under the License. 137c478bd9Sstevel@tonic-gate# 147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate# 207c478bd9Sstevel@tonic-gate# CDDL HEADER END 217c478bd9Sstevel@tonic-gate# 227c478bd9Sstevel@tonic-gate# 23*250a0733Sth199096# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate# Use is subject to license terms. 257c478bd9Sstevel@tonic-gate# 267c478bd9Sstevel@tonic-gate#pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate# Start/stop processes required for server NFS 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate. /lib/svc/share/smf_include.sh 316927f468Sdpzone=`smf_zonename` 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gatecase "$1" in 347c478bd9Sstevel@tonic-gate'start') 357c478bd9Sstevel@tonic-gate # The NFS server is not supported in a local zone 366927f468Sdp if smf_is_nonglobalzone; then 373fd3a04aSthurlow /usr/sbin/svcadm disable -t svc:/network/nfs/server 387c478bd9Sstevel@tonic-gate echo "The NFS server is not supported in a local zone" 397c478bd9Sstevel@tonic-gate sleep 5 & 407c478bd9Sstevel@tonic-gate exit $SMF_EXIT_OK 417c478bd9Sstevel@tonic-gate fi 427c478bd9Sstevel@tonic-gate 436185db85Sdougm # Share all file systems enabled for sharing. sharemgr understands 446185db85Sdougm # regular shares and ZFS shares and will handle both. Technically, 456185db85Sdougm # the shares would have been started long before getting here since 466185db85Sdougm # nfsd has a dependency on them. 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate startnfsd=0 497c478bd9Sstevel@tonic-gate 506185db85Sdougm # restart stopped shares from the repository 516185db85Sdougm /usr/sbin/sharemgr start -P nfs -a 52fa9e4066Sahrens 53fa9e4066Sahrens # Start up mountd and nfsd if anything is exported. 54fa9e4066Sahrens 557c478bd9Sstevel@tonic-gate if /usr/bin/grep -s nfs /etc/dfs/sharetab >/dev/null; then 567c478bd9Sstevel@tonic-gate startnfsd=1 577c478bd9Sstevel@tonic-gate fi 587c478bd9Sstevel@tonic-gate 5939c23413Seschrock # If auto-enable behavior is disabled, always start nfsd 6039c23413Seschrock 6139c23413Seschrock if [ `svcprop -p application/auto_enable nfs/server` = "false" ]; then 6239c23413Seschrock startnfsd=1 6339c23413Seschrock fi 6439c23413Seschrock 657c478bd9Sstevel@tonic-gate # Options for nfsd are now set in /etc/default/nfs 667c478bd9Sstevel@tonic-gate if [ $startnfsd -ne 0 ]; then 677c478bd9Sstevel@tonic-gate /usr/lib/nfs/mountd 68*250a0733Sth199096 rc=$? 69*250a0733Sth199096 if [ $rc != 0 ]; then 70*250a0733Sth199096 /usr/sbin/svcadm mark -t maintenance svc:/network/nfs/server 71*250a0733Sth199096 echo "$0: mountd failed with $rc" 72*250a0733Sth199096 sleep 5 & 73*250a0733Sth199096 exit $SMF_EXIT_ERR_FATAL 74*250a0733Sth199096 fi 75*250a0733Sth199096 767c478bd9Sstevel@tonic-gate /usr/lib/nfs/nfsd 77*250a0733Sth199096 rc=$? 78*250a0733Sth199096 if [ $rc != 0 ]; then 79*250a0733Sth199096 /usr/sbin/svcadm mark -t maintenance svc:/network/nfs/server 80*250a0733Sth199096 echo "$0: nfsd failed with $rc" 81*250a0733Sth199096 sleep 5 & 82*250a0733Sth199096 exit $SMF_EXIT_ERR_FATAL 83*250a0733Sth199096 fi 847c478bd9Sstevel@tonic-gate else 853fd3a04aSthurlow /usr/sbin/svcadm disable -t svc:/network/nfs/server 867c478bd9Sstevel@tonic-gate echo "No NFS filesystems are shared" 877c478bd9Sstevel@tonic-gate sleep 5 & 887c478bd9Sstevel@tonic-gate fi 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate ;; 917c478bd9Sstevel@tonic-gate 923fd3a04aSthurlow'refresh') 936185db85Sdougm /usr/sbin/sharemgr start -P nfs -a 943fd3a04aSthurlow ;; 953fd3a04aSthurlow 967c478bd9Sstevel@tonic-gate'stop') 977c478bd9Sstevel@tonic-gate /usr/bin/pkill -x -u 0,1 -z $zone '(nfsd|mountd)' 987c478bd9Sstevel@tonic-gate 996185db85Sdougm # Unshare all shared file systems using NFS 100fa9e4066Sahrens 1016185db85Sdougm /usr/sbin/sharemgr stop -P nfs -a 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate # 1047c478bd9Sstevel@tonic-gate # Wait up to 10 seconds for nfslogd to gracefully handle SIGHUP 1057c478bd9Sstevel@tonic-gate # 1067c478bd9Sstevel@tonic-gate /usr/bin/pkill -HUP -x -u 0 -z $zone nfslogd 1077c478bd9Sstevel@tonic-gate wtime=10 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate while [ $wtime -gt 0 ]; do 1107c478bd9Sstevel@tonic-gate /usr/bin/pgrep -x -u 0 -z $zone nfslogd >/dev/null || break 1117c478bd9Sstevel@tonic-gate wtime=`expr $wtime - 1` 1127c478bd9Sstevel@tonic-gate sleep 1 1137c478bd9Sstevel@tonic-gate done 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate # 1167c478bd9Sstevel@tonic-gate # Kill nfslogd more forcefully if it did not shutdown during 1177c478bd9Sstevel@tonic-gate # the grace period 1187c478bd9Sstevel@tonic-gate # 1197c478bd9Sstevel@tonic-gate if [ $wtime -eq 0 ]; then 1207c478bd9Sstevel@tonic-gate /usr/bin/pkill -TERM -x -u 0 -z $zone nfslogd 1217c478bd9Sstevel@tonic-gate fi 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate # Kill any processes left in service contract 1247c478bd9Sstevel@tonic-gate smf_kill_contract $2 TERM 1 1257c478bd9Sstevel@tonic-gate [ $? -ne 0 ] && exit 1 1267c478bd9Sstevel@tonic-gate ;; 1273fd3a04aSthurlow 1287c478bd9Sstevel@tonic-gate*) 1293fd3a04aSthurlow echo "Usage: $0 { start | stop | refresh }" 1307c478bd9Sstevel@tonic-gate exit 1 1317c478bd9Sstevel@tonic-gate ;; 1327c478bd9Sstevel@tonic-gateesac 1337c478bd9Sstevel@tonic-gateexit $SMF_EXIT_OK 134