Project

General

Profile

« Previous | Next » 

Revision 3781

Added by daigle over 16 years ago

Restore after accidental deletion

View differences:

bin/buildIndex.sh
1
#!/bin/sh
2
#This script will send a buildIndex command to 
3
#remote metacat with docid parameter. Then metacat will build index for this docid.
4
#This script will have one argument - it is a text file name which contains docid list.
5
#The text file will look like
6
#nceas.1.1
7
#nceas.2.1
8
#nceas.3.1
9

  
10
if  [ $# -ne 1 ]
11
 then
12
    echo "USAGE: $0 docidfile"
13
    exit 1
14
fi 
15
echo 'Please type metacat url (It should look like "http://pacific.msi.ucsb.edu:8080/knb/metacat")'
16
read metacatBaseURL
17
echo 'Please type KNB user name (It should look like "uid=tao,o=NCEAS,dc=ecoinformatics,dc=org")'
18
read username
19
echo 'Please type password'
20
read password
21
date
22
#login to metacat
23
loginurl="$metacatBaseURL?action=login&username=$username&password=$password"
24
wget -q -O - --save-cookies cookies --keep-session-cookies "$loginurl"
25

  
26
suffix="?action=buildindex"
27
metacatURL="$metacatBaseURL$suffix"
28

  
29
FILE=$1
30
# make sure file exist and readable
31
if [ ! -f $FILE ]; then 
32
  	echo "$FILE : does not exists"
33
  	exit 1
34
elif [ ! -r $FILE ]; then
35
  	echo "$FILE: can not read"
36
  	exit 2
37
fi
38

  
39

  
40
index=0
41
length=3
42
# read $FILE using the file descriptors
43
exec 3<&0
44
exec 0<$FILE
45
while read line
46
do
47
    if [ "$line" != "" ]
48
    then
49
      # construct metacat with given length of docid
50
      metacatURL="$metacatURL&docid=$line"
51
      index=`expr $index + 1`
52
	    if [ $index -eq $length ]
53
	    then
54
	       echo "here is url $metacatURL"
55
	       wget -q -O - --load-cookies cookies "$metacatURL"
56
	       index=0;
57
	       metacatURL="$metacatBaseURL$suffix"
58
	    fi
59
	fi		
60
done
61

  
62
#This will send out some remained docid
63
if [ $index -ne 0 ]
64
then   
65
    echo "here is url $metacatURL"
66
    wget -q -O - --load-cookies cookies "$metacatURL"
67
fi
68

  
69
exec 0<&3
70
date
71
exit 0
0 72

  
bin/measure-metacat-query-performance.sh
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. Since we need restart postgres,
4
#this script should be run as root user
5
#Note: before running the script, user should run both "ant jar" and "ant clientjar"
6
#in Metacat to get metaca-client.jar and metacat.jar in build directory. 
7

  
8
#variables
9
JUNIT=/usr/local/devtools/apache-ant/lib/junit-4.3.1.jar
10
METACAT=../build/metacat.jar
11
METACAT_CLIENT=../build/metacat-client.jar
12
UTILITIES=../lib/utilities.jar
13
METACATURL=http://chico.dyndns.org:8081/knb/metacat
14
QUERY=../test/performance_measure_query
15
TIME=2
16
TOMCATUSER=tao
17

  
18
#copy the java client to build directory
19
rm -rf ../build/tests/
20
mkdir ../build/tests
21
mkdir ../build/tests/edu
22
mkdir ../build/tests/edu/ucsb
23
mkdir ../build/tests/edu/ucsb/nceas
24
mkdir ../build/tests/edu/ucsb/nceas/metacattest
25
cp ../test/edu/ucsb/nceas/metacattest/MetaCatQueryPerformanceTest.java ../build/tests/edu/ucsb/nceas/metacattest/.
26

  
27
#compile the class
28
javac -classpath $JUNIT:$METACAT:$METACAT_CLIENT:$UTILITIES ../build/tests/edu/ucsb/nceas/metacattest/MetaCatQueryPerformanceTest.java 
29

  
30

  
31

  
32

  
33
#Iterate to restart postgres and tomcat, and call java client class
34
for (( i = 0; i < $TIME; i++))
35
do
36
    #retart postgres
37
    /etc/init.d/postgresql-8.2 restart
38
    #Check if posgres restart successfully
39
    successPQL=false;
40
    while [ $successPQL = false ]
41
    do
42
      #if found netstat command has posgres lisenter is ready,
43
      #reset the success value to jump the while loop.
44
      for fn in `netstat -plt | grep postgres`
45
      do
46
        #reset success value
47
        successPQL=true
48
      done
49
    done
50
    echo "success value for restarting postgres is $successPQL"
51

  
52
    #stop tomcat
53
    su - $TOMCATUSER /usr/local/devtools/apache-tomcat-5.5.23/bin/shutdown.sh
54
     #Check if tomcat start successfully
55
    successStop=false;
56
    tomcatRunning=false
57
    while [ $successStop = false ]
58
    do
59
      #if found netstat command still has tcomat lisenter (port 8005) ,
60
      #reset the tomcatRunning value to true
61
      for fn in `netstat -plt | grep 8005`
62
      do
63
        #reset success value
64
        tomcatRunning=true;
65
      done
66
      if [ $tomcatRunning = true ]
67
         then
68
           successStop=false
69
         else
70
           successStop=true
71
      fi
72
    done
73
    echo "success value for stoping tomcat is $successStop"
74
     
75
    #start tomcat
76
   su - $TOMCATUSER  /usr/local/devtools/apache-tomcat-5.5.23/bin/startup.sh
77
    #Check if tomcat start successfully
78
    successStart=false;
79
    while [ $successStart = false ]
80
    do
81
      #if found netstat command has tcomat lisenter (port 8005) is ready,
82
      #reset the success value to jump the while loop.
83
      for fn in `netstat -plt | grep 8005`
84
      do
85
        #reset success value
86
        successStart=true
87
      done
88
    done
89
    echo "success value for starting tomcat is $successStart"
90

  
91

  
92
    #run the class -- query the remote metacat
93
    java -cp $JUNIT:$METACAT:$METACAT_CLIENT:$UTILITIES:../build/tests edu.ucsb.nceas.metacattest.MetaCatQueryPerformanceTest $METACATURL $QUERY
94
    echo "Successfully query the metacat"
95
done
0 96

  
bin/backup-metacat.sh
1
#!/bin/sh
2

  
3
#
4
# Backup files needed for metacat.  This script creates a temporary directory,
5
# backs up the postgres database, metacat data files, and ldap directory, and 
6
# then creates a gzipped tar file from those files.  It then writes the backup
7
# file to a DVD drive and then cleans up any old backup files.
8
#
9
# To run this file, install it in /usr/sbin or a similar location and add an
10
# entry in the root user's crontab to run the command periodically.  The
11
# following crontab entry would run it every night at 2:00 am
12
# 0 2 * * *       /usr/sbin/backup-metacat.sh >> $HOME/cron-output 2>&1
13
#
14
# This is really just an example script and may not work in your environment
15
# uless you modify it appropriately.
16
#
17
# 13 March 2006 Matt Jones
18

  
19
# Name of the metacat database in postgres to be backed up
20
DBNAME=metacat
21

  
22
# The day of the week on which the DVD is swapped (1-7, 1=Monday)
23
# This must be correct or else the write to DVD will not work
24
SWAPDAY=2
25

  
26
# Number of days of backups to keep online, anything older is removed
27
DAYSTOKEEP=7
28

  
29
# Device to be used for the DVD writer -- this may vary on your system
30
DVD=/dev/dvd
31

  
32
#
33
# Below here lie demons
34
#
35

  
36
# Set up our umask to protect files from prying eyes
37
umask 007
38

  
39
# Make a temp dir for the backed up files
40
TAG=`date +%F-%H%M%S`
41
DATADIR="/var/metacat"
42
ARCHROOT="/var/metacat/metacat-backup"
43
mkdir $ARCHROOT
44
chgrp postgres $ARCHROOT
45
chmod g+rwxs $ARCHROOT
46

  
47
ARCHNAME="metacat-backup-$TAG"
48
ARCHDIR="$ARCHROOT/$ARCHNAME"
49
mkdir $ARCHDIR
50

  
51
# Shut down the tomcat server so nobody else changes anything while we backup
52
/etc/init.d/tomcat stop
53

  
54
# Shut down ldap too
55
/etc/init.d/slapd stop
56

  
57
# Backup postgres
58
su - postgres -c "pg_dump $DBNAME > $ARCHDIR/metacat-postgres-backup.sql"
59

  
60
# Backup the data files
61
tar czf $ARCHDIR/datafiles-backup.tgz --exclude=$ARCHROOT $DATADIR
62

  
63
# Backup LDAP to an LDIF file
64
slapcat -l $ARCHDIR/$DBNAME-ldap.ldif
65

  
66
# Restart LDAP
67
/etc/init.d/slapd start
68

  
69
# Restart tomcat
70
/etc/init.d/tomcat start
71

  
72
# Tar up the archive and copy it to archive media
73
cd $ARCHROOT
74
tar czf $ARCHDIR.tgz $ARCHNAME
75

  
76
# Clean up the temp files
77
rm -rf $ARCHDIR
78

  
79
# Write the backup file to DVD
80
DAY=`date +%u`
81
DVDFLAG=-M
82
if [ $DAY == $SWAPDAY ] ; then
83
  DVDFLAG=-Z
84
fi
85
growisofs $DVDFLAG $DVD -R -J $ARCHDIR.tgz
86

  
87
# clean up any of the backup files that are older than DAYSTOKEEP
88
find $ARCHROOT -mtime +$DAYSTOKEEP -exec rm -f {} \;
0 89

  
bin/measure-metacat-query-performance2.sh
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 -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
 
0 89

  
bin/check_shape_file_existence.sh
1
#!/bin/bash
2
#This file will check if shape files exist or not.
3
#If one is deleted and a email will be sent to tao with the tomcat log.
4
#Note: if file eml_message already exists in current dir, email wouldn't send again.
5
#This setting will make sure only one email will sent. Otherwise, my email account will be over quota.
6
target_file1=/var/www/org.ecoinformatics.knb/knb/data/metacat_shps/data_points.dbf
7
target_file2=/var/www/org.ecoinformatics.knb/knb/data/metacat_shps/data_points.shp
8
target_file3=/var/www/org.ecoinformatics.knb/knb/data/metacat_shps/data_points.shx
9
target_file4=/var/www/org.ecoinformatics.knb/knb/data/metacat_shps/data_bounds.dbf
10
target_file5=/var/www/org.ecoinformatics.knb/knb/data/metacat_shps/data_bounds.shp
11
target_file6=/var/www/org.ecoinformatics.knb/knb/data/metacat_shps/data_bounds.shx
12

  
13
log_file=/var/log/tomcat/catalina.out
14
sender_email_address=knb_tomcat@ecoinformatics.org
15
receiver_email_address=tao@nceas.ucsb.edu
16
tmp=/root/email_message
17
if [ ! -e $target_file1 -o ! -e $target_file2 -o ! -e $target_file3 -o ! -e $target_file4 -o ! -e $target_file5 -o ! -e $target_file6 ]
18
 then
19
   if [ ! -e $tmp ]
20
     then
21
       touch $tmp && chmod 600 $tmp
22
       echo -e "subject: Shape file was deleted at `date`\n" > $tmp
23
       echo -e "\n log file info: " >> $tmp
24
       echo -e "\n `tail -300 $log_file`" >> $tmp
25
       /usr/sbin/sendmail -f $sender_email_address $receiver_email_address < $tmp
26
   fi
27
fi
0 28

  

Also available in: Unified diff