Project

General

Profile

1 4656 daigle
#!/bin/bash
2
3
LONG_DATE=`date +%Y%m%d%H%M%S`
4
5 6558 leinfelder
TOMCAT_USER=tomcat6
6
TOMCAT_HOME=/usr/share/tomcat6
7 4656 daigle
SOURCE_DIR=/usr/share/metacat-@metacatVersion@
8
9
###############################################################################
10
# Install metacat war file
11
###############################################################################
12
13
## Stop tomcat
14
echo "Stopping Tomcat"
15 6558 leinfelder
/etc/init.d/tomcat6 stop
16 4656 daigle
17
## backup the old war file
18
if [ -e ${TOMCAT_HOME}/webapps/knb.war ]
19
then
20
  echo "Backing up ${TOMCAT_HOME}/webapps/knb.war to ${TOMCAT_HOME}/webapps/knb.war.${LONG_DATE}"
21
  mv ${TOMCAT_HOME}/webapps/knb.war ${TOMCAT_HOME}/webapps/knb.war.${LONG_DATE}
22
fi
23
24
## remove the knb application directory
25
if [ -d ${TOMCAT_HOME}/webapps/knb ]
26
then
27
  echo "Removing the old metacat application directorties"
28
  rm -rf ${TOMCAT_HOME}/webapps/knb
29
fi
30
31
## copy the new war file into the webapps directory
32
echo copying new knb.war file to ${TOMCAT_HOME}/webapps/knb.war
33
cp ${SOURCE_DIR}/knb.war ${TOMCAT_HOME}/webapps/knb.war
34
35
## expand the war file
36
CURR_DIR=`pwd`
37
38
## make knb directory and extract knb.war into it.
39
echo "Making knb application directory: ${TOMCAT_HOME}/webapps/knb"
40
mkdir ${TOMCAT_HOME}/webapps/knb
41
cd ${TOMCAT_HOME}/webapps/knb
42
43
echo "extracting knb.war into ${TOMCAT_HOME}/webapps/knb"
44
jar -xvf ${TOMCAT_HOME}/webapps/knb.war > /dev/null
45
chown -R ${TOMCAT_USER} ${TOMCAT_HOME}/webapps/knb
46
echo cd to $CURR_DIR
47
cd $CURR_DIR
48
49
chmod -R  +x ${TOMCAT_HOME}/webapps/knb/cgi-bin
50
51
###############################################################################
52
# Create Metacat External File Space
53
###############################################################################
54
55
## Create the /var/metacat directory
56
if [ ! -d /var/metacat ]
57
then
58
  echo "Making Metacat utility directory: /var/metacat"
59
  mkdir /var/metacat
60
fi
61
62
## Change the ownership of the /var/metacat directory to be the tomcat user.
63
echo "changing ownership of /var/metacat to ${TOMCAT_USER}"
64
chown -R ${TOMCAT_USER} /var/metacat
65
66
###############################################################################
67
# Configure Tomcat
68
###############################################################################
69
70
## Change ownership of the tomcat directories to be the tomcat user
71
echo "changing ownership of ${TOMCAT_HOME} to ${TOMCAT_USER}"
72
chown -R ${TOMCAT_USER} ${TOMCAT_HOME}
73 6558 leinfelder
echo "changing ownership of /var/lib/tomcat6 to ${TOMCAT_USER}"
74
chown -R ${TOMCAT_USER} /var/lib/tomcat6
75
echo "changing ownership of /etc/tomcat6 to ${TOMCAT_USER}"
76
chown -R ${TOMCAT_USER} /etc/tomcat6
77 4656 daigle
78
79
###############################################################################
80
# Configure Apache
81
###############################################################################
82
83
## Stop apache
84
echo "Stopping Apache"
85
/etc/init.d/apache2 stop
86
87
## copy in jk.conf file
88
if [ -e /etc/apache2/mods-available/jk.conf ]
89
then
90
  JK_CONF_DIFF=`diff ${SOURCE_DIR}/jk.conf /etc/apache2/mods-available/jk.conf`
91
  if [ "${JK_CONF_DIFF}" != "" ]
92
  then
93
    echo "Backing up /etc/apache2/mods-available/jk.conf to /etc/apache2/mods-available/jk.conf.${LONG_DATE}"
94
    mv /etc/apache2/mods-available/jk.conf /etc/apache2/mods-available/jk.conf.${LONG_DATE}
95
  fi
96
fi
97
echo "Copying jk.conf to /etc/apache2/mods-available/"
98
cp ${SOURCE_DIR}/jk.conf /etc/apache2/mods-available/
99
100
## copy in workers.properties file
101
if [ -e /etc/apache2/workers.properties ]
102
then
103
  WORKERS_PROPS_DIFF=`diff ${SOURCE_DIR}/workers.properties /etc/apache2/workers.properties`
104
  if [ "${WORKERS_PROPS_DIFF}" != "" ]
105
  then
106
    echo "Backing up /etc/apache2/workers.properties to /etc/apache2/workers.properties.${LONG_DATE}"
107
    mv /etc/apache2/workers.properties /etc/apache2/workers.properties.${LONG_DATE}
108
  fi
109
fi
110
echo "Copying workers.properties to /etc/apache2/"
111
cp ${SOURCE_DIR}/workers.properties /etc/apache2/
112
113
## disable and then re-enable mod jk to pick up changes
114
echo "Refreshing Mod JK"
115
a2dismod jk
116
a2enmod jk
117
118
## copy in knb site file
119
if [ -e /etc/apache2/sites-available/knb ]
120
then
121
  KNB_SITE_DIFF=`diff ${SOURCE_DIR}/knb /etc/apache2/sites-available/knb`
122
  if [ "${KNB_SITE_DIFF}" != "" ]
123
  then
124
    echo "Backing up /etc/apache2/sites-available/knb to /etc/apache2/sites-available/knb.${LONG_DATE}"
125
    mv /etc/apache2/sites-available/knb /etc/apache2/sites-available/knb.${LONG_DATE}
126
  fi
127
fi
128
echo "Copying knb site file to /etc/apache2/sites-available/"
129
cp ${SOURCE_DIR}/knb /etc/apache2/sites-available/
130
131
## enable knb site
132
echo "Enabling knb site"
133
a2dissite knb
134
a2ensite knb
135
136
###############################################################################
137
# Configure Postgres
138
###############################################################################
139
140
## modify pg_hba.conf
141
PG_HBA_IS_MODIFIED=`grep "metacat metacat" /etc/postgresql/8.3/main/pg_hba.conf`
142
if [ "${PG_HBA_IS_MODIFIED}" == "" ]
143
then
144
  echo "backing up /etc/postgresql/8.3/main/pg_hba.conf to /etc/postgresql/8.3/main/pg_hba.conf.${LONG_DATE}"
145
  cp /etc/postgresql/8.3/main/pg_hba.conf /etc/postgresql/8.3/main/pg_hba.conf.${LONG_DATE}
146
147
  echo "appending 'host metacat metacat 127.0.0.1 255.255.255.255 password' to /etc/postgresql/8.3/main/pg_hba.conf"
148
  echo "host metacat metacat 127.0.0.1 255.255.255.255 password" >> /etc/postgresql/8.3/main/pg_hba.conf
149
fi
150
151
## create metacat schema and user
152
echo "Creating metacat database schema"
153
su postgres -c "createdb metacat"
154
155
echo "Creating metacat user"
156
su postgres -c "psql -c \"CREATE USER metacat WITH UNENCRYPTED PASSWORD 'metacat'\""
157
158
## Restart the postgres db
159
echo "Restarting postgres database"
160
/etc/init.d/postgresql-8.3 restart
161
162
###############################################################################
163
# Start Apache and Tomcat
164
###############################################################################
165
166
## Start Apache
167
/etc/init.d/apache2 start
168
169
## ugly hack to fix circular dependency bug that will keep tomcat
170
## from starting within this script
171
if [ ! -f /etc/java-1.5.0-sun/jvm.cfg ]; then
172
  temp_jvm_cfg=/etc/java-1.5.0-sun/jvm.cfg
173
  mkdir -p /etc/java-1.5.0-sun
174
  printf -- "-server KNOWN\n" > $temp_jvm_cfg
175
fi
176
177
## Start Tomcat
178
echo "starting Tomcat server"
179
180
#export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun
181 6558 leinfelder
#/usr/share/tomcat6/bin/startup.sh
182 4656 daigle
183 6558 leinfelder
/etc/init.d/tomcat6 start
184 4656 daigle
#chmod u+x ${SOURCE_DIR}/delay-tomcat-start
185
#${SOURCE_DIR}/delay-tomcat-start &