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 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 # ident "@(#)srv_setup.ksh 1.1 09/04/27 SMI"
28 #
29
30 #
31 # setup the $SERVER for testing NFS V4 recovery testing by:
32 # first removing LOFI file systems setup prior to recovery
33 # test execution. Setup server with testfiles, export it,
34 # start reboot/restart daemon.
35 #
36
37 NAME=$(basename $0)
38
39 SetDebugMode
40 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
41 && set -x
42
43 id | grep "0(root)" > /dev/null 2>&1
44 if (( $? != 0 )); then
45 echo "$NAME: ERROR - Must be root to run this script for setup."
46 exit 1
47 fi
48
49 Usage="Usage: $NAME -s | -r | -c \n
50 -s: to setup this host w/daemon, testfiles, and share\n
51 -r: restore share after reboot\n
52 -c: to cleanup the server\n
53 "
54
55 if (( $# < 1 )); then
56 echo "$NAME: ERROR - incorrect usage."
57 echo $Usage
58 exit 2
59 fi
60
61 ENVFILE=ENV_from_client
62 STF_TMPDIR=Tmpdir_from_client
63 NFSUTILFILE=NFS_UTIL
64 TestZFS=TEST_ZFS
65 SHRDIR=SHR_DIR
66 SHROPT=SHR_OPT
67 SHRGRP=SHR_GRP
68
69 # source the environment/config file from client to be consistent
70 . $STF_TMPDIR/$ENVFILE
71 . $STF_TMPDIR/$NFSUTILFILE
72
73 getopts src opt
74 case $opt in
75 s)
76 # make sure nfs4red reboot/reset-nfsd daemon is running
77 chmod +x $STF_TMPDIR/nfs4red > /dev/null 2>&1
78 $STF_TMPDIR/nfs4red > /dev/null 2>&1 &
79 ps -e | grep -w "nfs4red" > /dev/null
80 if (( $? != 0 )); then
81 $STF_TMPDIR/nfs4red > /dev/null 2>&1 &
82 fi
83
84 echo "Done - setup nfs4red OKAY."
85 rm -f ${STF_TMPDIR}/*.out.$$ ${STF_TMPDIR}/err.*
86 ;;
87
88 r)
89 # restore share mount
90 # check already shared
91 shared=$(share | grep $SHRDIR)
92 [[ -n $shared ]] && exit 0
93
94 sharemgr_share $SHRGRP $SHRDIR $SHROPT
95 if (( $? != 0 )); then
96 exit 3
97 fi
98 ;;
99
100 c)
101 pkill -x -u 0 nfs4red
102
103 echo "Done - recovery cleanup of test filesystems/daemons OKAY"
104 cd $STF_TMPDIR
105 rm -f *.out.* recov_setserver nfs4red /etc/rc3.d/S99nfs4red
106 ;;
107
108 \?)
109 echo $Usage
110 exit 2
111 ;;
112 esac
113
114 exit 0