10Sstevel@tonic-gate#!/sbin/sh 20Sstevel@tonic-gate# 30Sstevel@tonic-gate# CDDL HEADER START 40Sstevel@tonic-gate# 50Sstevel@tonic-gate# The contents of this file are subject to the terms of the 61573Sdp# Common Development and Distribution License (the "License"). 71573Sdp# You may not use this file except in compliance with the License. 80Sstevel@tonic-gate# 90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate# See the License for the specific language governing permissions 120Sstevel@tonic-gate# and limitations under the License. 130Sstevel@tonic-gate# 140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate# 200Sstevel@tonic-gate# CDDL HEADER END 210Sstevel@tonic-gate# 220Sstevel@tonic-gate# 23*13080SPavan.Mettu@Oracle.COM# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 240Sstevel@tonic-gate# 250Sstevel@tonic-gate 260Sstevel@tonic-gate# Start/stop processes required for server NFS 270Sstevel@tonic-gate 280Sstevel@tonic-gate. /lib/svc/share/smf_include.sh 298823STruong.Q.Nguyen@Sun.COM. /lib/svc/share/ipf_include.sh 301573Sdpzone=`smf_zonename` 310Sstevel@tonic-gate 328823STruong.Q.Nguyen@Sun.COM# 338823STruong.Q.Nguyen@Sun.COM# Handling a corner case here. If we were in offline state due to an 348823STruong.Q.Nguyen@Sun.COM# unsatisfied dependency, the ipf_method process wouldn't have generated 358823STruong.Q.Nguyen@Sun.COM# the ipfilter configuration. When we transition to online because the 368823STruong.Q.Nguyen@Sun.COM# dependency is satisfied, the start method will have to generate the 378823STruong.Q.Nguyen@Sun.COM# ipfilter configuration. To avoid all possible deadlock scenarios, 388823STruong.Q.Nguyen@Sun.COM# we restart ipfilter which will regenerate the ipfilter configuration 398823STruong.Q.Nguyen@Sun.COM# for the entire system. 408823STruong.Q.Nguyen@Sun.COM# 418823STruong.Q.Nguyen@Sun.COM# The ipf_method process signals that it didn't generate ipf rules by 428823STruong.Q.Nguyen@Sun.COM# removing the service's ipf file. Thus we only restart network/ipfilter 438823STruong.Q.Nguyen@Sun.COM# when the file is missing. 448823STruong.Q.Nguyen@Sun.COM# 458823STruong.Q.Nguyen@Sun.COMconfigure_ipfilter() 468823STruong.Q.Nguyen@Sun.COM{ 478823STruong.Q.Nguyen@Sun.COM ipfile=`fmri_to_file $SMF_FMRI $IPF_SUFFIX` 488823STruong.Q.Nguyen@Sun.COM [ -f "$ipfile" ] && return 0 498823STruong.Q.Nguyen@Sun.COM 508823STruong.Q.Nguyen@Sun.COM # 518823STruong.Q.Nguyen@Sun.COM # Nothing to do if: 528823STruong.Q.Nguyen@Sun.COM # - ipfilter isn't online 538823STruong.Q.Nguyen@Sun.COM # - global policy is 'custom' 548823STruong.Q.Nguyen@Sun.COM # - service's policy is 'use_global' 558823STruong.Q.Nguyen@Sun.COM # 568823STruong.Q.Nguyen@Sun.COM service_check_state $IPF_FMRI $SMF_ONLINE || return 0 578823STruong.Q.Nguyen@Sun.COM [ "`get_global_def_policy`" = "custom" ] && return 0 588823STruong.Q.Nguyen@Sun.COM [ "`get_policy $SMF_FMRI`" = "use_global" ] && return 0 598823STruong.Q.Nguyen@Sun.COM 608823STruong.Q.Nguyen@Sun.COM svcadm restart $IPF_FMRI 618823STruong.Q.Nguyen@Sun.COM} 628823STruong.Q.Nguyen@Sun.COM 630Sstevel@tonic-gatecase "$1" in 640Sstevel@tonic-gate'start') 650Sstevel@tonic-gate # The NFS server is not supported in a local zone 661573Sdp if smf_is_nonglobalzone; then 67330Sthurlow /usr/sbin/svcadm disable -t svc:/network/nfs/server 680Sstevel@tonic-gate echo "The NFS server is not supported in a local zone" 690Sstevel@tonic-gate sleep 5 & 700Sstevel@tonic-gate exit $SMF_EXIT_OK 710Sstevel@tonic-gate fi 720Sstevel@tonic-gate 733034Sdougm # Share all file systems enabled for sharing. sharemgr understands 743034Sdougm # regular shares and ZFS shares and will handle both. Technically, 753034Sdougm # the shares would have been started long before getting here since 763034Sdougm # nfsd has a dependency on them. 770Sstevel@tonic-gate 780Sstevel@tonic-gate startnfsd=0 790Sstevel@tonic-gate 803034Sdougm # restart stopped shares from the repository 813034Sdougm /usr/sbin/sharemgr start -P nfs -a 82789Sahrens 83789Sahrens # Start up mountd and nfsd if anything is exported. 84789Sahrens 850Sstevel@tonic-gate if /usr/bin/grep -s nfs /etc/dfs/sharetab >/dev/null; then 860Sstevel@tonic-gate startnfsd=1 870Sstevel@tonic-gate fi 880Sstevel@tonic-gate 893377Seschrock # If auto-enable behavior is disabled, always start nfsd 903377Seschrock 913377Seschrock if [ `svcprop -p application/auto_enable nfs/server` = "false" ]; then 923377Seschrock startnfsd=1 933377Seschrock fi 943377Seschrock 95*13080SPavan.Mettu@Oracle.COM # Options for nfsd are now set in SMF 960Sstevel@tonic-gate if [ $startnfsd -ne 0 ]; then 970Sstevel@tonic-gate /usr/lib/nfs/mountd 986859Sth199096 rc=$? 996859Sth199096 if [ $rc != 0 ]; then 1006859Sth199096 /usr/sbin/svcadm mark -t maintenance svc:/network/nfs/server 1016859Sth199096 echo "$0: mountd failed with $rc" 1026859Sth199096 sleep 5 & 1036859Sth199096 exit $SMF_EXIT_ERR_FATAL 1046859Sth199096 fi 1056859Sth199096 1060Sstevel@tonic-gate /usr/lib/nfs/nfsd 1076859Sth199096 rc=$? 1086859Sth199096 if [ $rc != 0 ]; then 1096859Sth199096 /usr/sbin/svcadm mark -t maintenance svc:/network/nfs/server 1106859Sth199096 echo "$0: nfsd failed with $rc" 1116859Sth199096 sleep 5 & 1126859Sth199096 exit $SMF_EXIT_ERR_FATAL 1136859Sth199096 fi 1148823STruong.Q.Nguyen@Sun.COM 1158823STruong.Q.Nguyen@Sun.COM configure_ipfilter 1160Sstevel@tonic-gate else 117330Sthurlow /usr/sbin/svcadm disable -t svc:/network/nfs/server 1180Sstevel@tonic-gate echo "No NFS filesystems are shared" 1190Sstevel@tonic-gate sleep 5 & 1200Sstevel@tonic-gate fi 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate ;; 1230Sstevel@tonic-gate 124330Sthurlow'refresh') 1253034Sdougm /usr/sbin/sharemgr start -P nfs -a 126330Sthurlow ;; 127330Sthurlow 1280Sstevel@tonic-gate'stop') 1290Sstevel@tonic-gate /usr/bin/pkill -x -u 0,1 -z $zone '(nfsd|mountd)' 1300Sstevel@tonic-gate 1313034Sdougm # Unshare all shared file systems using NFS 132789Sahrens 1333034Sdougm /usr/sbin/sharemgr stop -P nfs -a 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate # 1360Sstevel@tonic-gate # Wait up to 10 seconds for nfslogd to gracefully handle SIGHUP 1370Sstevel@tonic-gate # 1380Sstevel@tonic-gate /usr/bin/pkill -HUP -x -u 0 -z $zone nfslogd 1390Sstevel@tonic-gate wtime=10 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate while [ $wtime -gt 0 ]; do 1420Sstevel@tonic-gate /usr/bin/pgrep -x -u 0 -z $zone nfslogd >/dev/null || break 1430Sstevel@tonic-gate wtime=`expr $wtime - 1` 1440Sstevel@tonic-gate sleep 1 1450Sstevel@tonic-gate done 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate # 1480Sstevel@tonic-gate # Kill nfslogd more forcefully if it did not shutdown during 1490Sstevel@tonic-gate # the grace period 1500Sstevel@tonic-gate # 1510Sstevel@tonic-gate if [ $wtime -eq 0 ]; then 1520Sstevel@tonic-gate /usr/bin/pkill -TERM -x -u 0 -z $zone nfslogd 1530Sstevel@tonic-gate fi 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate # Kill any processes left in service contract 1560Sstevel@tonic-gate smf_kill_contract $2 TERM 1 1570Sstevel@tonic-gate [ $? -ne 0 ] && exit 1 1580Sstevel@tonic-gate ;; 159330Sthurlow 1608823STruong.Q.Nguyen@Sun.COM'ipfilter') 1618823STruong.Q.Nguyen@Sun.COM # 1628823STruong.Q.Nguyen@Sun.COM # NFS related services are RPC. nfs/server has nfsd which has 1638823STruong.Q.Nguyen@Sun.COM # well-defined port number but mountd is an RPC daemon. 1648823STruong.Q.Nguyen@Sun.COM # 1658823STruong.Q.Nguyen@Sun.COM # Essentially, we generate rules for the following "services" 1668823STruong.Q.Nguyen@Sun.COM # - nfs/server which has nfsd and mountd 1678823STruong.Q.Nguyen@Sun.COM # - nfs/rquota 1688823STruong.Q.Nguyen@Sun.COM # 1698823STruong.Q.Nguyen@Sun.COM # The following services are enabled for both nfs client and 1708823STruong.Q.Nguyen@Sun.COM # server so we'll treat them as client services and simply 1718823STruong.Q.Nguyen@Sun.COM # allow incoming traffic. 1728823STruong.Q.Nguyen@Sun.COM # - nfs/status 1738823STruong.Q.Nguyen@Sun.COM # - nfs/nlockmgr 1748823STruong.Q.Nguyen@Sun.COM # - nfs/cbd 1758823STruong.Q.Nguyen@Sun.COM # 1768823STruong.Q.Nguyen@Sun.COM NFS_FMRI="svc:/network/nfs/server:default" 1778823STruong.Q.Nguyen@Sun.COM RQUOTA_FMRI="svc:/network/nfs/rquota:default" 1788823STruong.Q.Nguyen@Sun.COM FMRI=$2 1798823STruong.Q.Nguyen@Sun.COM 1808823STruong.Q.Nguyen@Sun.COM file=`fmri_to_file $FMRI $IPF_SUFFIX` 1818823STruong.Q.Nguyen@Sun.COM echo "# $FMRI" >$file 1828823STruong.Q.Nguyen@Sun.COM policy=`get_policy $NFS_FMRI` 1838823STruong.Q.Nguyen@Sun.COM ip="any" 1848823STruong.Q.Nguyen@Sun.COM 1858823STruong.Q.Nguyen@Sun.COM # 1868823STruong.Q.Nguyen@Sun.COM # nfs/server configuration is processed in the start method. 1878823STruong.Q.Nguyen@Sun.COM # 1888823STruong.Q.Nguyen@Sun.COM if [ "$FMRI" = "$NFS_FMRI" ]; then 1898823STruong.Q.Nguyen@Sun.COM service_check_state $FMRI $SMF_ONLINE 1908823STruong.Q.Nguyen@Sun.COM if [ $? -ne 0 ]; then 1918823STruong.Q.Nguyen@Sun.COM rm $file 1928823STruong.Q.Nguyen@Sun.COM exit $SMF_EXIT_OK 1938823STruong.Q.Nguyen@Sun.COM fi 1948823STruong.Q.Nguyen@Sun.COM 1958823STruong.Q.Nguyen@Sun.COM nfs_name=`svcprop -p $FW_CONTEXT_PG/name $FMRI 2>/dev/null` 1968823STruong.Q.Nguyen@Sun.COM tport=`$SERVINFO -p -t -s $nfs_name 2>/dev/null` 1978823STruong.Q.Nguyen@Sun.COM if [ -n "$tport" ]; then 1988823STruong.Q.Nguyen@Sun.COM generate_rules $FMRI $policy "tcp" $ip $tport $file 1998823STruong.Q.Nguyen@Sun.COM fi 2008823STruong.Q.Nguyen@Sun.COM 2018823STruong.Q.Nguyen@Sun.COM uport=`$SERVINFO -p -u -s $nfs_name 2>/dev/null` 2028823STruong.Q.Nguyen@Sun.COM if [ -n "$uport" ]; then 2038823STruong.Q.Nguyen@Sun.COM generate_rules $FMRI $policy "udp" $ip $uport $file 2048823STruong.Q.Nguyen@Sun.COM fi 2058823STruong.Q.Nguyen@Sun.COM 2068823STruong.Q.Nguyen@Sun.COM tports=`$SERVINFO -R -p -t -s "mountd" 2>/dev/null` 2078823STruong.Q.Nguyen@Sun.COM if [ -n "$tports" ]; then 2088823STruong.Q.Nguyen@Sun.COM for tport in $tports; do 2098823STruong.Q.Nguyen@Sun.COM generate_rules $FMRI $policy "tcp" $ip \ 2108823STruong.Q.Nguyen@Sun.COM $tport $file 2118823STruong.Q.Nguyen@Sun.COM done 2128823STruong.Q.Nguyen@Sun.COM fi 2138823STruong.Q.Nguyen@Sun.COM 2148823STruong.Q.Nguyen@Sun.COM uports=`$SERVINFO -R -p -u -s "mountd" 2>/dev/null` 2158823STruong.Q.Nguyen@Sun.COM if [ -n "$uports" ]; then 2168823STruong.Q.Nguyen@Sun.COM for uport in $uports; do 2178823STruong.Q.Nguyen@Sun.COM generate_rules $FMRI $policy "udp" $ip \ 2188823STruong.Q.Nguyen@Sun.COM $uport $file 2198823STruong.Q.Nguyen@Sun.COM done 2208823STruong.Q.Nguyen@Sun.COM fi 2218823STruong.Q.Nguyen@Sun.COM 2228823STruong.Q.Nguyen@Sun.COM elif [ "$FMRI" = "$RQUOTA_FMRI" ]; then 2238823STruong.Q.Nguyen@Sun.COM iana_name=`svcprop -p inetd/name $FMRI` 2248823STruong.Q.Nguyen@Sun.COM 2258823STruong.Q.Nguyen@Sun.COM tports=`$SERVINFO -R -p -t -s $iana_name 2>/dev/null` 2268823STruong.Q.Nguyen@Sun.COM if [ -n "$tports" ]; then 2278823STruong.Q.Nguyen@Sun.COM for tport in $tports; do 2288823STruong.Q.Nguyen@Sun.COM generate_rules $NFS_FMRI $policy "tcp" \ 2298823STruong.Q.Nguyen@Sun.COM $ip $tport $file 2308823STruong.Q.Nguyen@Sun.COM done 2318823STruong.Q.Nguyen@Sun.COM fi 2328823STruong.Q.Nguyen@Sun.COM 2338823STruong.Q.Nguyen@Sun.COM uports=`$SERVINFO -R -p -u -s $iana_name 2>/dev/null` 2348823STruong.Q.Nguyen@Sun.COM if [ -n "$uports" ]; then 2358823STruong.Q.Nguyen@Sun.COM for uport in $uports; do 2368823STruong.Q.Nguyen@Sun.COM generate_rules $NFS_FMRI $policy "udp" \ 2378823STruong.Q.Nguyen@Sun.COM $ip $uport $file 2388823STruong.Q.Nguyen@Sun.COM done 2398823STruong.Q.Nguyen@Sun.COM fi 2408823STruong.Q.Nguyen@Sun.COM else 2418823STruong.Q.Nguyen@Sun.COM # 2428823STruong.Q.Nguyen@Sun.COM # Handle the client services here 2438823STruong.Q.Nguyen@Sun.COM # 2448823STruong.Q.Nguyen@Sun.COM restarter=`svcprop -p general/restarter $FMRI 2>/dev/null` 2458823STruong.Q.Nguyen@Sun.COM if [ "$restarter" = "$INETDFMRI" ]; then 2468823STruong.Q.Nguyen@Sun.COM iana_name=`svcprop -p inetd/name $FMRI` 2478823STruong.Q.Nguyen@Sun.COM isrpc=`svcprop -p inetd/isrpc $FMRI` 2488823STruong.Q.Nguyen@Sun.COM else 2498823STruong.Q.Nguyen@Sun.COM iana_name=`svcprop -p $FW_CONTEXT_PG/name $FMRI` 2508823STruong.Q.Nguyen@Sun.COM isrpc=`svcprop -p $FW_CONTEXT_PG/isrpc $FMRI` 2518823STruong.Q.Nguyen@Sun.COM fi 2528823STruong.Q.Nguyen@Sun.COM 2538823STruong.Q.Nguyen@Sun.COM if [ "$isrpc" = "true" ]; then 2548823STruong.Q.Nguyen@Sun.COM tports=`$SERVINFO -R -p -t -s $iana_name 2>/dev/null` 2558823STruong.Q.Nguyen@Sun.COM uports=`$SERVINFO -R -p -u -s $iana_name 2>/dev/null` 2568823STruong.Q.Nguyen@Sun.COM else 2578823STruong.Q.Nguyen@Sun.COM tports=`$SERVINFO -p -t -s $iana_name 2>/dev/null` 2588823STruong.Q.Nguyen@Sun.COM uports=`$SERVINFO -p -u -s $iana_name 2>/dev/null` 2598823STruong.Q.Nguyen@Sun.COM fi 2608823STruong.Q.Nguyen@Sun.COM 2618823STruong.Q.Nguyen@Sun.COM if [ -n "$tports" ]; then 2628823STruong.Q.Nguyen@Sun.COM for tport in $tports; do 2638823STruong.Q.Nguyen@Sun.COM echo "pass in log quick proto tcp from any" \ 2648823STruong.Q.Nguyen@Sun.COM "to any port = ${tport} flags S " \ 2658823STruong.Q.Nguyen@Sun.COM "keep state" >>${file} 2668823STruong.Q.Nguyen@Sun.COM done 2678823STruong.Q.Nguyen@Sun.COM fi 2688823STruong.Q.Nguyen@Sun.COM 2698823STruong.Q.Nguyen@Sun.COM if [ -n "$uports" ]; then 2708823STruong.Q.Nguyen@Sun.COM for uport in $uports; do 2718823STruong.Q.Nguyen@Sun.COM echo "pass in log quick proto udp from any" \ 2728823STruong.Q.Nguyen@Sun.COM "to any port = ${uport}" >>${file} 2738823STruong.Q.Nguyen@Sun.COM done 2748823STruong.Q.Nguyen@Sun.COM fi 2758823STruong.Q.Nguyen@Sun.COM fi 2768823STruong.Q.Nguyen@Sun.COM 2778823STruong.Q.Nguyen@Sun.COM ;; 2788823STruong.Q.Nguyen@Sun.COM 2790Sstevel@tonic-gate*) 280330Sthurlow echo "Usage: $0 { start | stop | refresh }" 2810Sstevel@tonic-gate exit 1 2820Sstevel@tonic-gate ;; 2830Sstevel@tonic-gateesac 2840Sstevel@tonic-gateexit $SMF_EXIT_OK 285