1 #!/bin/bash 2 3 # Mount an NFS export for remote log storage. 4 5 # Copyright (C) 2003-2006 IBM 6 # 7 # This program is free software; you can redistribute it and/or 8 # modify it under the terms of the GNU General Public License as 9 # published by the Free Software Foundation; either version 2 of the 10 # License, or (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, but 13 # WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 # General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 # 02111-1307, USA. 21 22 # @author Sarunya Jimenez (sjimen (at] us.ibm.com) 23 # Reworked by Darrick Wong <djwong (at] us.ibm.com> 24 # - If unable to connect to NFS_SERVER => save log files in local machine 25 # - Otherwise, 26 # 1. log files produced from ./pounder will be in 27 # NFS_LOGSERVER (e.g. 10.0.0.211) 28 # |--- /pounder 29 # |--- /$HOSTNAME (e.g. testbox) 30 # |--- KERNEL_VERSION-ARCH (e.g. 2.6.14-i686) 31 # 2. Run "$./pounder -u" to umount nfs log server 32 # Otherwise, by default, when ./pounder completed, nfs remains 33 # mounted to the local machine. 34 # ASSUMPTION : Already imported global variables from "libpounder.sh" 35 36 if [ -z "$NFS_LOGSERVER" -o -z "$NFS_LOGDIR" ]; then 37 echo "NFS log server not configured." 38 exit 0 39 fi 40 41 # Path construction: 42 43 #nfsserv:/crash/pounder-logs/testbox/2.6.14-i686/somedate/ 44 #$NFS_LOGSERVER:$NFS_LOGDIR/$NFS_LOGLOCAL/$DATE 45 46 #/home/pounder/log 47 #$POUNDER_LOGLOCAL 48 49 #/home/pounder/log/somedate 50 #$POUNDER_LOGDIR or $POUNDER_LOGLOCAL/$DATE 51 52 # Are we already mounted? 53 IS_MOUNTED=`grep "$POUNDER_LOGLOCAL " /proc/mounts | wc -l` 54 if [ $IS_MOUNTED -eq 1 ]; then 55 echo "Log directory already mounted on $POUNDER_LOGLOCAL" 56 exit 0 57 fi 58 59 # Create local directory for mounting 60 mkdir -p "$POUNDER_LOGLOCAL/" 61 if [ ! -d "$POUNDER_LOGLOCAL/" ]; then 62 echo "Cannot create $POUNDER_LOGLOCAL/." 63 exit 1 64 fi 65 66 # Mount NFS log server's top-level log dir 67 mount "$NFS_LOGSERVER:$NFS_LOGDIR/" "$POUNDER_LOGLOCAL/" -t nfs -o tcp 68 RESULT=$? 69 70 if [ $RESULT -gt 0 ]; then 71 echo "Mounting $NFS_LOGSERVER:$NFS_LOGDIR/ on $POUNDER_LOGLOCAL/ failed; logs will be local." 72 exit 2; 73 fi 74 75 # Create a directory for this run's log files 76 mkdir -p "$POUNDER_LOGLOCAL/$NFS_LOGLOCAL/" 77 if [ ! -d "$POUNDER_LOGLOCAL/$NFS_LOGLOCAL/" ]; then 78 echo "Cannot create local log dir on log server $POUNDER_LOGLOCAL/$NFS_LOGLOCAL/; logs will be local." 79 umount "$POUNDER_LOGLOCAL/" 80 exit 3 81 fi 82 83 # Now remount the real log dir on our local machine. 84 umount "$POUNDER_LOGLOCAL/" 85 mount "$NFS_LOGSERVER:$NFS_LOGDIR/$NFS_LOGLOCAL/" "$POUNDER_LOGLOCAL/" -t nfs -o tcp 86 RESULT=$? 87 88 if [ $RESULT -gt 0 ]; then 89 echo "Mounting $NFS_LOGSERVER:$NFS_LOGDIR/$NFS_LOGLOCAL on $POUNDER_LOGLOCAL/ failed; logs will be local." 90 exit 4; 91 fi 92 93 # Once we return to pounder, it'll create $POUNDER_LOGDIR. 94 95 exit 0 96