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
28 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
29
30 NAME=`basename $0`
31 CDIR=`pwd`
32
33 id | grep "0(root)" > /dev/null 2>&1
34 if [ $? -ne 0 ]; then
35 echo "$NAME: This script require root permission to run."
36 exit 99
37 fi
38
39 CONFIGFILE=CONFIGFILE_from_client
40 CONFIGDIR=CONFIGDIR_from_client
41 TMPDIR=Tmpdir_from_client
42
43 function smf_is_present
44 {
45 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
46 smf_include="/lib/svc/share/smf_include.sh"
47 [ ! -r ${smf_include} ] && return 1
48
49 . ${smf_include}
50
51 smf_present
52 }
53
54 # sourcing framework global environment variables created after go_setup
55 # and for this purpose only this file should be sourced
56 if [[ ! -f $CONFIGFILE ]]; then
57 echo "$NAME: CONFIGFILE[$CONFIGFILE] not found;"
58 echo "\texit UNINITIATED."
59 exit 6
60 fi
61 . $CONFIGFILE
62
63 NOTICEDIR=$BASEDIR/._Notice__Dir_.
64
65 [ ! -d $NOTICEDIR ] && mkdir -m 0777 -p $NOTICEDIR || chmod 0777 $NOTICEDIR
66
67 fmri=svc:/network/nfs/server:default
68 timeout=10
69
70 while :; do
71 sleep 2
72 action=`ls -d $NOTICEDIR/re* 2>/dev/null | nawk -F\/ '{print $NF}'`
73
74 case $action in
75 reset-nfsd)
76 echo "Restarting the 'nfsd' in `uname -n` ..."
77 rm -f $NOTICEDIR/DONE_reset
78 if smf_is_present; then
79 svcadm disable ${fmri}
80 fi
81
82 pkill -x -u 0 nfsd
83 sleep 1
84
85 if smf_is_present; then
86 svcadm enable ${fmri}
87 timer=${timeout}
88 else
89 /usr/lib/nfs/nfsd
90 timer=5
91 fi
92 i=1
93 while [ $i -le $timer ]
94 do
95 pgrep nfsd > /dev/null 2>&1
96 if [ $? -eq 0 ]; then
97 i="OK"
98 break
99 fi
100 i=`expr $i + 1`
101 sleep 1
102 done
103 if [ $i = "OK" ]; then
104 echo "ReSet NFSD(`pgrep nfsd`) started" \
105 > $NOTICEDIR/DONE_reset
106 else
107 echo "ReSet nfsd FAILed" > $NOTICEDIR/DONE_reset
108 fi
109 ;;
110 reboot)
111 echo "Rebooting `uname -n`, please wait ..."
112 rm -f $NOTICEDIR/DONE_reboot
113 rm -f $NOTICEDIR/re*
114 sync; sync; reboot
115 ;;
116 requit)
117 rm -f $NOTICEDIR/re*
118 break;;
119 *)
120 continue;;
121
122 esac
123 rm -f $NOTICEDIR/re*
124 done
125 exit 0