Project

General

Profile

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/knb/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 $PROJECT/build/tests
25
mkdir $PROJECT/build/tests/edu
26
mkdir $PROJECT/build/tests/edu/ucsb
27
mkdir $PROJECT/build/tests/edu/ucsb/nceas
28
mkdir $PROJECT/build/tests/edu/ucsb/nceas/metacattest
29
cp $PROJECT/test/edu/ucsb/nceas/metacattest/MetaCatQueryPerformanceTest.java $PROJECT/build/tests/edu/ucsb/nceas/metacattest/.
30

    
31
#compile the class
32
javac -classpath $JUNIT:$METACAT:$METACAT_CLIENT:$UTILITIES $PROJECT/build/tests/edu/ucsb/nceas/metacattest/MetaCatQueryPerformanceTest.java 
33

    
34

    
35
case "$1" in
36
  start)
37
    echo "Starting running query script"
38
    #Iterate to restart postgres and tomcat, and call java client class
39
    TIMES=`cat $TIMEFILE`
40
    echo "The value from TIMEFILE is $TIMES" 
41
    #if times greater than 0, it will query the metacat
42
    if [ $TIMES -gt 0 ]
43
      then
44
      #Check if postgres start successfully
45
      successPQL=false;
46
      while [ $successPQL = false ]
47
         do
48
             #if found netstat command has posgres lisenter is ready,
49
             #reset the success value to jump the while loop.
50
             for fn in `netstat -plt | grep postgres`
51
               do
52
                 #reset success value
53
                 successPQL=true
54
            done
55
      done
56
      echo "success value for starting postgres is $successPQL"
57
      #Check if tomcat start successfully
58
      successStart=false;
59
      while [ $successStart = false ]
60
        do
61
           #if found netstat command has tcomat lisenter (port 8005) is ready,
62
           #reset the success value to jump the while loop.
63
           for fn in `netstat -plt | grep 8005`
64
             do
65
                #reset success value
66
                successStart=true
67
           done
68
      done
69
     echo "success value for starting tomcat is $successStart"
70
     #run the class -- query the remote metacat
71
      java -cp $JUNIT:$METACAT:$METACAT_CLIENT:$UTILITIES:$PROJECT/build/tests edu.ucsb.nceas.metacattest.MetaCatQueryPerformanceTest $METACATURL $QUERY
72
      echo "Successfully query the metacat"
73
      #Drecease 1 from value of TIMES
74
      TIMES=`expr $TIMES - 1`
75
      echo "The new TIMES value  is $TIMES"
76
      #write the new TIMES to the file
77
      echo $TIMES >$TIMEFILE
78
      #reboot machine
79
      reboot
80
    fi
81
   ;;
82
 stop)
83
    echo "Stopping running query script - do nothing"
84
     ;;
85
  *)
86
    echo "Usage: /etc/init.d/blah {start|stop}"
87
    exit 1
88
    ;;
89
esac
90

    
91
exit 0
92
 
(5-5/5)