1 |
3293
|
tao
|
#!/bin/bash
|
2 |
|
|
#Call a java client class to query metacat automatically and metacat server
|
3 |
|
|
#will record the performance data into a file. This script will be put in /etc/init.d directory
|
4 |
|
|
#and called in system booting. After script is down, it will call reboot system too.
|
5 |
|
|
#So every time to excecute the quyer, memory will be in fresh.
|
6 |
|
|
#Note: before running the script, user should run both "ant jar" and "ant clientjar"
|
7 |
|
|
#in Metacat to get metaca-client.jar and metacat.jar in build directory.
|
8 |
|
|
|
9 |
|
|
#variables
|
10 |
|
|
JUNIT=/usr/local/devtools/apache-ant/lib/junit-4.3.1.jar
|
11 |
|
|
PROJECT=/home/tao/project/metacat
|
12 |
|
|
METACAT=$PROJECT/build/metacat.jar
|
13 |
|
|
METACAT_CLIENT=$PROJECT/build/metacat-client.jar
|
14 |
|
|
UTILITIES=$PROJECT/lib/utilities.jar
|
15 |
|
|
METACATURL=http://chico.dyndns.org:8081/knb/metacat
|
16 |
|
|
QUERY=$PROJECT/test/performance_measure_query
|
17 |
|
|
TIMEFILE=$PROJECT/test/times
|
18 |
|
|
TOMCATUSER=tao
|
19 |
|
|
|
20 |
|
|
#copy the java client to build directory
|
21 |
|
|
rm -rf $PROJECT/build/tests/
|
22 |
|
|
mkdir $PROJECT/build/tests
|
23 |
|
|
mkdir $PROJECT/build/tests/edu
|
24 |
|
|
mkdir $PROJECT/build/tests/edu/ucsb
|
25 |
|
|
mkdir $PROJECT/build/tests/edu/ucsb/nceas
|
26 |
|
|
mkdir $PROJECT/build/tests/edu/ucsb/nceas/metacattest
|
27 |
|
|
cp $PROJECT/test/edu/ucsb/nceas/metacattest/MetaCatQueryPerformanceTest.java $PROJECT/build/tests/edu/ucsb/nceas/metacattest/.
|
28 |
|
|
|
29 |
|
|
#compile the class
|
30 |
|
|
javac -classpath $JUNIT:$METACAT:$METACAT_CLIENT:$UTILITIES $PROJECT/build/tests/edu/ucsb/nceas/metacattest/MetaCatQueryPerformanceTest.java
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
case "$1" in
|
34 |
|
|
start)
|
35 |
|
|
echo "Starting running query script"
|
36 |
|
|
#Iterate to restart postgres and tomcat, and call java client class
|
37 |
|
|
TIMES=`cat $TIMEFILE`
|
38 |
|
|
echo "The value from TIMEFILE is $TIMES"
|
39 |
|
|
#if times greater than 0, it will query the metacat
|
40 |
|
|
if [ $TIMES -gt 0 ]
|
41 |
|
|
then
|
42 |
|
|
#Check if postgres start successfully
|
43 |
|
|
successPQL=false;
|
44 |
|
|
while [ $successPQL = false ]
|
45 |
|
|
do
|
46 |
|
|
#if found netstat command has posgres lisenter is ready,
|
47 |
|
|
#reset the success value to jump the while loop.
|
48 |
|
|
for fn in `netstat -plt | grep postgres`
|
49 |
|
|
do
|
50 |
|
|
#reset success value
|
51 |
|
|
successPQL=true
|
52 |
|
|
done
|
53 |
|
|
done
|
54 |
|
|
echo "success value for starting postgres is $successPQL"
|
55 |
|
|
#Check if tomcat start successfully
|
56 |
|
|
successStart=false;
|
57 |
|
|
while [ $successStart = false ]
|
58 |
|
|
do
|
59 |
|
|
#if found netstat command has tcomat lisenter (port 8005) is ready,
|
60 |
|
|
#reset the success value to jump the while loop.
|
61 |
|
|
for fn in `netstat -plt | grep 8005`
|
62 |
|
|
do
|
63 |
|
|
#reset success value
|
64 |
|
|
successStart=true
|
65 |
|
|
done
|
66 |
|
|
done
|
67 |
|
|
echo "success value for starting tomcat is $successStart"
|
68 |
|
|
#run the class -- query the remote metacat
|
69 |
|
|
java -cp $JUNIT:$METACAT:$METACAT_CLIENT:$UTILITIES:$PROJECT/build/tests edu.ucsb.nceas.metacattest.MetaCatQueryPerformanceTest $METACATURL $QUERY
|
70 |
|
|
echo "Successfully query the metacat"
|
71 |
|
|
#Drecease 1 from value of TIMES
|
72 |
|
|
TIMES=`expr $TIMES - 1`
|
73 |
|
|
echo "The new TIMES value is $TIMES"
|
74 |
|
|
#write the new TIMES to the file
|
75 |
|
|
echo $TIMES >$TIMEFILE
|
76 |
|
|
#reboot machine
|
77 |
|
|
reboot
|
78 |
|
|
fi
|
79 |
|
|
;;
|
80 |
|
|
stop)
|
81 |
|
|
echo "Stopping running query script - do nothing"
|
82 |
|
|
;;
|
83 |
|
|
*)
|
84 |
|
|
echo "Usage: /etc/init.d/blah {start|stop}"
|
85 |
|
|
exit 1
|
86 |
|
|
;;
|
87 |
|
|
esac
|
88 |
|
|
|
89 |
|
|
exit 0
|