1
|
#!/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
|
METACATURL=http://chico.dyndns.org:8081/metacat/metacat
|
13
|
TOMCATUSER=tao
|
14
|
|
15
|
|
16
|
QUERY=$PROJECT/test/performance_measure_query
|
17
|
TIMEFILE=$PROJECT/test/times
|
18
|
METACAT=$PROJECT/build/metacat.jar
|
19
|
METACAT_CLIENT=$PROJECT/build/metacat-client.jar
|
20
|
UTILITIES=$PROJECT/lib/utilities.jar
|
21
|
|
22
|
#copy the java client to build directory
|
23
|
rm -rf $PROJECT/build/tests/
|
24
|
mkdir -p $PROJECT/build/tests/edu/ucsb/nceas/metacattest
|
25
|
cp $PROJECT/test/edu/ucsb/nceas/metacattest/MetaCatQueryPerformanceTest.java $PROJECT/build/tests/edu/ucsb/nceas/metacattest/.
|
26
|
|
27
|
#compile the class
|
28
|
javac -classpath $JUNIT:$METACAT:$METACAT_CLIENT:$UTILITIES $PROJECT/build/tests/edu/ucsb/nceas/metacattest/MetaCatQueryPerformanceTest.java
|
29
|
|
30
|
|
31
|
case "$1" in
|
32
|
start)
|
33
|
echo "Starting running query script"
|
34
|
#Iterate to restart postgres and tomcat, and call java client class
|
35
|
TIMES=`cat $TIMEFILE`
|
36
|
echo "The value from TIMEFILE is $TIMES"
|
37
|
#if times greater than 0, it will query the metacat
|
38
|
if [ $TIMES -gt 0 ]
|
39
|
then
|
40
|
#Check if postgres start successfully
|
41
|
successPQL=false;
|
42
|
while [ $successPQL = false ]
|
43
|
do
|
44
|
#if found netstat command has posgres lisenter is ready,
|
45
|
#reset the success value to jump the while loop.
|
46
|
for fn in `netstat -plt | grep postgres`
|
47
|
do
|
48
|
#reset success value
|
49
|
successPQL=true
|
50
|
done
|
51
|
done
|
52
|
echo "success value for starting postgres is $successPQL"
|
53
|
#Check if tomcat start successfully
|
54
|
successStart=false;
|
55
|
while [ $successStart = false ]
|
56
|
do
|
57
|
#if found netstat command has tcomat lisenter (port 8005) is ready,
|
58
|
#reset the success value to jump the while loop.
|
59
|
for fn in `netstat -plt | grep 8005`
|
60
|
do
|
61
|
#reset success value
|
62
|
successStart=true
|
63
|
done
|
64
|
done
|
65
|
echo "success value for starting tomcat is $successStart"
|
66
|
#run the class -- query the remote metacat
|
67
|
java -cp $JUNIT:$METACAT:$METACAT_CLIENT:$UTILITIES:$PROJECT/build/tests edu.ucsb.nceas.metacattest.MetaCatQueryPerformanceTest $METACATURL $QUERY
|
68
|
echo "Successfully query the metacat"
|
69
|
#Drecease 1 from value of TIMES
|
70
|
TIMES=`expr $TIMES - 1`
|
71
|
echo "The new TIMES value is $TIMES"
|
72
|
#write the new TIMES to the file
|
73
|
echo $TIMES >$TIMEFILE
|
74
|
#reboot machine
|
75
|
reboot
|
76
|
fi
|
77
|
;;
|
78
|
stop)
|
79
|
echo "Stopping running query script - do nothing"
|
80
|
;;
|
81
|
*)
|
82
|
echo "Usage: /etc/init.d/blah {start|stop}"
|
83
|
exit 1
|
84
|
;;
|
85
|
esac
|
86
|
|
87
|
exit 0
|
88
|
|