1 #! /usr/bin/ksh -p
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 #
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 # A script to kill and restart nfsd upon request
28
29 [[ -n "$DEBUG" ]] && [[ $DEBUG != 0 ]] && set -x
30
31 . $TESTROOT/libsmf.shlib
32
33 NAME=$(basename $0)
34
35 id | grep "0(root)" > /dev/null 2>&1
36 if [[ $? -ne 0 ]]; then
37 echo "$NAME: Must have root permission to run this script"
38 exit 99
39 fi
40
41 PATH=/usr/bin:/usr/sbin:$PATH
42 export PATH
43
44 # sourcing framework global environment variables created after go_setup
45 # and for this purpose only this file should be sourced
46 CONFIGFILE=/var/tmp/nfsv4/config/config.suite
47 if [[ ! -f $CONFIGFILE ]]; then
48 echo "$NAME: CONFIGFILE[$CONFIGFILE] not found;"
49 echo "\texit UNINITIATED."
50 exit 6
51 fi
52 . $CONFIGFILE
53
54 NOTICEDIR=$TMPDIR/.libmapid
55 [[ ! -d $NOTICEDIR ]] && mkdir -m 0777 -p $NOTICEDIR || chmod 0777 $NOTICEDIR
56
57 trap 'cd $NOTICEDIR; rm -f nfsd* DONE* *.$$; exit 99' 2 3 9
58
59 while true; do
60 sleep 2
61 action=`ls -d $NOTICEDIR/libmapid* 2>/dev/null | nawk -F\/ '{print $NF}'`
62
63 case $action in
64
65 libmapid_modify_nfscfg)
66 rm -f $NOTICEDIR/DONE
67
68 cp /etc/default/nfs $TMPDIR/etc.default.nfs.$$.orig \
69 && sed '/NFSMAPID_DOMAIN/d' /etc/default/nfs \
70 > $TMPDIR/etc.default.nfs.$$.temp \
71 && mv $TMPDIR/etc.default.nfs.$$.temp /etc/default/nfs \
72 && echo "NFSMAPID_DOMAIN=libmapid.test.domain" >> /etc/default/nfs
73 if [[ $? -eq 0 ]]; then
74 echo "Modify /etc/default/nfs ... OK" > $NOTICEDIR/DONE
75 else
76 echo "Modify /etc/default/nfs ... FAILED" > $NOTICEDIR/DONE
77 fi
78
79 rm -f $NOTICEDIR/libmapid_modify_nfscfg
80 ;;
81
82 libmapid_restore_nfscfg)
83 rm -f $NOTICEDIR/DONE
84
85 mv $TMPDIR/etc.default.nfs.$$.orig /etc/default/nfs
86 if [[ $? -eq 0 ]]; then
87 echo "Restore /etc/default/nfs...OK">$NOTICEDIR/DONE
88 else
89 echo "Restore /etc/default/nfs...FAILED">$NOTICEDIR/DONE
90 fi
91
92 rm -f $NOTICEDIR/libmapid_restore_nfscfg
93 ;;
94
95 libmapid_start_dns)
96 rm -f $NOTICEDIR/DONE
97
98 smf_fmri_transition_state \
99 do svc:/network/dns/server:default online 120
100 if [ $? -eq 0 ]; then
101 echo "Start DNS...OK" > $NOTICEDIR/DONE
102 else
103 echo "Start DNS...FAILED" > $NOTICEDIR/DONE
104 fi
105
106 rm -f $NOTICEDIR/libmapid_start_dns
107 ;;
108
109 libmapid_shutdown_dns)
110 rm -f $NOTICEDIR/DONE
111
112 smf_fmri_transition_state \
113 do svc:/network/dns/server:default disabled 120
114 if [[ $? -eq 0 ]]; then
115 echo "Shutdown DNS...OK" > $NOTICEDIR/DONE
116 else
117 echo "Shutdown DNS...FAILED" > $NOTICEDIR/DONE
118 fi
119
120 rm -f $NOTICEDIR/libmapid_shutdown_dns
121 ;;
122
123 libmapid_quit)
124 rm -rf $NOTICEDIR;
125 break;;
126
127 *)
128 continue;;
129 esac
130 done
131 exit 0