1 |
< |
### RPM cms dbs-server DBS_1_0_8 |
1 |
> |
### RPM cms dbs-server DBS_2_0_8_pre5 |
2 |
> |
|
3 |
> |
%define cvstag %{realversion} |
4 |
> |
# define version of DBS to use, it's schema version |
5 |
> |
%define dbs_version %{realversion} |
6 |
|
|
3 |
– |
%define cvstag %v |
7 |
|
Source: cvs://:pserver:anonymous@cmscvs.cern.ch:2401/cvs_server/repositories/CMSSW?passwd=AA_:yZZ3e&module=DBS/Servers/JavaServer&export=DBS&tag=-r%{cvstag}&output=/dbs-server.tar.gz |
8 |
< |
Requires: apache-ant mysql oracle apache-tomcat |
6 |
< |
#Requires: apache-ant mysql oracle apache-tomcat java-jdk |
7 |
< |
#Requires: apache-ant apache-tomcat |
8 |
> |
Requires: apache-ant mysql mysql-deployment oracle apache-tomcat java-jdk dbs-schema dbs-libs |
9 |
|
|
10 |
|
%prep |
11 |
|
%setup -n DBS |
12 |
+ |
# kill running mysql|tomcat under my account since build is over |
13 |
+ |
ps -w -w -f -u`whoami` | egrep "mysqld|tomcat" | grep -v egrep | awk '{print "kill -9 "$2""}' |/bin/sh |
14 |
+ |
|
15 |
|
%build |
16 |
+ |
# DBS wants to have LibValut attached to DBS top-level dir, required by build.xml file |
17 |
+ |
ln -s $DBS_LIBS_ROOT/lib LibValut |
18 |
|
echo "PWD=$PWD" |
19 |
|
cd Servers/JavaServer |
20 |
+ |
|
21 |
+ |
# retrieve which DBS schema to use |
22 |
+ |
#export DBS_SCHEMA=`grep "^use " $DBS_SCHEMA_ROOT/lib/Schema/NeXtGen/DBS-NeXtGen-MySQL_DEPLOYABLE.sql | awk '{print $2}' | sed "s/;//g"` |
23 |
+ |
#export DBS_SCHEMA_VERSION=`cat $DBS_SCHEMA_ROOT/lib/Schema/NeXtGen/DBS-NeXtGen-MySQL_DEPLOYABLE.sql | grep "INSERT INTO SchemaVersion" | awk '{split($0,a,"\x27"); print a[2]}'` |
24 |
+ |
|
25 |
+ |
# fix context.xml file |
26 |
+ |
cat etc/context.xml.tobe | sed "s/__insert_username__/dbs/g" | sed "s/__insert_password__/cmsdbs/g" | sed "s/3306/3316/g" | sed "s/maxActive=\"0\"/maxActive=\"100\"/g" > etc/context.xml |
27 |
+ |
|
28 |
+ |
# compile DBS server code |
29 |
+ |
mkdir -p bin/WEB-INF/lib |
30 |
|
echo "PWD=$PWD" |
31 |
+ |
source $JAVA_JDK_ROOT/etc/profile.d/init.sh |
32 |
+ |
export JAVA_HOME=$JAVA_JDK_ROOT |
33 |
|
ant --noconfig dist |
34 |
|
cd ../../ |
35 |
|
|
36 |
|
%install |
37 |
< |
mkdir -p %{i}/Servers/JavaServer/ |
37 |
> |
mkdir -p %{i}/Servers/JavaServer/bin/WEB-INF/lib |
38 |
|
cp -r Servers/JavaServer/* %{i}/Servers/JavaServer |
39 |
+ |
ln -s $DBS_LIBS_ROOT/lib %{i}/LibValut |
40 |
|
|
41 |
|
# copy war file |
42 |
|
cp %{i}/Servers/JavaServer/DBS.war $APACHE_TOMCAT_ROOT/webapps |
43 |
|
|
44 |
+ |
# create dbs init script |
45 |
+ |
mkdir -p %{i}/Servers/JavaServer/bin |
46 |
+ |
cat > %{i}/Servers/JavaServer/bin/dbs_init.sh << DBS_INIT_EOF |
47 |
+ |
#!/bin/sh |
48 |
+ |
export MYAREA=rpm_install_area |
49 |
+ |
export SCRAM_ARCH=slc4_ia32_gcc345 |
50 |
+ |
export APT_VERSION=0.5.15lorg3.2-cmp |
51 |
+ |
source \$MYAREA/\$SCRAM_ARCH/external/apt/\$APT_VERSION/etc/profile.d/init.sh |
52 |
+ |
source \$MYAREA/%{pkgrel}/etc/profile.d/init.sh |
53 |
+ |
# set DBS DBs |
54 |
+ |
MYSQL_PORT=3316 |
55 |
+ |
MYSQL_PATH=\$MYSQL_ROOT/mysqldb |
56 |
+ |
MYSQL_SOCK=\$MYSQL_PATH/mysql.sock |
57 |
+ |
MYSQL_PID=\$MYSQL_PATH/mysqld.pid |
58 |
+ |
MYSQL_ERR=\$MYSQL_PATH/error.log |
59 |
+ |
|
60 |
+ |
function dbs_stop() |
61 |
+ |
{ |
62 |
+ |
me=\`whoami\` |
63 |
+ |
echo $"Stop mysqld|tomcat running under \$me account from $MYAREA area..." |
64 |
+ |
ps -w -w -f -u\$me | grep mysqld | grep $MYAREA | grep \$MYSQL_PORT | grep -v grep | awk '{print "kill -9 "\$2""}'|/bin/sh |
65 |
+ |
ps -w -w -f -u\$me | grep tomcat | grep $MYAREA | grep -v grep | awk '{print "kill -9 "\$2""}'|/bin/sh |
66 |
+ |
} |
67 |
+ |
function dbs_start() |
68 |
+ |
{ |
69 |
+ |
echo "+++ Start up CMS MySQL daemon on port \${MYSQL_PORT} ..." |
70 |
+ |
\$MYSQL_ROOT/bin/mysqld_safe --datadir=\$MYSQL_PATH --port=\$MYSQL_PORT \ |
71 |
+ |
--socket=\$MYSQL_SOCK --log-error=\$MYSQL_ERR --pid-file=\$MYSQL_PID --max_allowed_packet=32M & |
72 |
+ |
echo "+++ Start tomcat server" |
73 |
+ |
\$APACHE_TOMCAT_ROOT/bin/catalina.sh start |
74 |
+ |
sleep 2 |
75 |
+ |
echo |
76 |
+ |
echo "DBS service is ready ..." |
77 |
+ |
} |
78 |
+ |
function dbs_status() |
79 |
+ |
{ |
80 |
+ |
me=\`whoami\` |
81 |
+ |
dbs_mysqld=\`ps -w -w -f -u\$me | egrep "mysqld" | grep $MYAREA | grep \$MYSQL_PORT| grep -v egrep | wc -l\` |
82 |
+ |
dbs_tomcat=\`ps -w -w -f -u\$me | egrep "tomcat" | grep $MYAREA | grep -v egrep | wc -l\` |
83 |
+ |
if [ \${dbs_tomcat} -ne 1 ]; then |
84 |
+ |
echo "Tomcat server is not running" |
85 |
+ |
break |
86 |
+ |
fi |
87 |
+ |
if [ \${dbs_mysqld} -ne 2 ]; then |
88 |
+ |
echo "MySQL server is not running" |
89 |
+ |
exit 1 |
90 |
+ |
fi |
91 |
+ |
ps -w -w -f -u\$me | grep $MYAREA | egrep "mysqld" | grep -v egrep | awk '{print "MySQLd server running, pid="\$2""}' |
92 |
+ |
ps -w -w -f -u\$me | grep $MYAREA | egrep "tomcat" | grep -v egrep | awk '{print "Tomcat server running, pid="\$2""}' |
93 |
+ |
echo "For more information please have a look at tomcat log:" |
94 |
+ |
echo "\$APACHE_TOMCAT_ROOT/logs/catalina.out" |
95 |
+ |
} |
96 |
+ |
|
97 |
+ |
RETVAL=\$? |
98 |
+ |
|
99 |
+ |
case "\$1" in |
100 |
+ |
restart) |
101 |
+ |
dbs_stop |
102 |
+ |
dbs_start |
103 |
+ |
;; |
104 |
+ |
start) |
105 |
+ |
dbs_start |
106 |
+ |
;; |
107 |
+ |
status) |
108 |
+ |
dbs_status |
109 |
+ |
;; |
110 |
+ |
stop) |
111 |
+ |
dbs_stop |
112 |
+ |
;; |
113 |
+ |
*) |
114 |
+ |
echo \$"Usage: \$0 {start|stop|status|restart}" |
115 |
+ |
exit 1 |
116 |
+ |
;; |
117 |
+ |
esac |
118 |
+ |
|
119 |
+ |
exit \$RETVAL |
120 |
+ |
DBS_INIT_EOF |
121 |
+ |
chmod a+x %{i}/Servers/JavaServer/bin/dbs_init.sh |
122 |
+ |
|
123 |
|
mkdir -p %{i}/etc/profile.d |
124 |
|
(echo "#!/bin/sh"; \ |
125 |
|
echo "source $ORACLE_ROOT/etc/profile.d/init.sh"; \ |
126 |
|
echo "source $MYSQL_ROOT/etc/profile.d/init.sh"; \ |
127 |
+ |
echo "source $MYSQL_DEPLOYMENT_ROOT/etc/profile.d/init.sh"; \ |
128 |
|
echo "source $APACHE_TOMCAT_ROOT/etc/profile.d/init.sh"; \ |
129 |
|
echo "source $APACHE_ANT_ROOT/etc/profile.d/init.sh"; \ |
130 |
+ |
echo "source $DBS_SCHEMA_ROOT/etc/profile.d/init.sh"; \ |
131 |
+ |
echo "source $DBS_LIBS_ROOT/etc/profile.d/init.sh"; \ |
132 |
|
echo "source $JAVA_JDK_ROOT/etc/profile.d/init.sh"; \ |
133 |
+ |
echo "export JAVA_HOME=$JAVA_JDK_ROOT" |
134 |
+ |
echo "export CATALINA_HOME=$APACHE_TOMCAT_ROOT" |
135 |
|
) > %{i}/etc/profile.d/dependencies-setup.sh |
136 |
|
|
137 |
|
(echo "#!/bin/tcsh"; \ |
138 |
|
echo "source $ORACLE_ROOT/etc/profile.d/init.csh"; \ |
139 |
|
echo "source $MYSQL_ROOT/etc/profile.d/init.csh"; \ |
140 |
+ |
echo "source $MYSQL_DEPLOYMENT_ROOT/etc/profile.d/init.csh"; \ |
141 |
|
echo "source $APACHE_TOMCAT_ROOT/etc/profile.d/init.csh"; \ |
142 |
|
echo "source $APACHE_ANT_ROOT/etc/profile.d/init.csh"; \ |
143 |
+ |
echo "source $DBS_SCHEMA_ROOT/etc/profile.d/init.csh"; \ |
144 |
+ |
echo "source $DBS_LIBS_ROOT/etc/profile.d/init.csh"; \ |
145 |
|
echo "source $JAVA_JDK_ROOT/etc/profile.d/init.csh"; \ |
146 |
+ |
echo "setenv JAVA_HOME $JAVA_JDK_ROOT" |
147 |
+ |
echo "setenv CATALINA_HOME $APACHE_TOMCAT_ROOT" |
148 |
|
) > %{i}/etc/profile.d/dependencies-setup.csh |
149 |
|
|
150 |
|
|
152 |
|
%{relocateConfig}etc/profile.d/dependencies-setup.sh |
153 |
|
%{relocateConfig}etc/profile.d/dependencies-setup.csh |
154 |
|
|
155 |
+ |
# setup MySQL server |
156 |
+ |
. $RPM_INSTALL_PREFIX/%{pkgrel}/etc/profile.d/init.sh |
157 |
+ |
VO_CMS_SW_DIR=`echo $DBS_SERVER_ROOT | awk '{split($1,a,SCRAM_ARCH); print a[1]}' SCRAM_ARCH=$SCRAM_ARCH` |
158 |
+ |
export VO_CMS_SW_DIR |
159 |
+ |
$MYSQL_DEPLOYMENT_ROOT/bin/mysql-deployment.sh |
160 |
+ |
|
161 |
+ |
# set DBS DBs |
162 |
+ |
MYSQL_PORT=3316 |
163 |
+ |
MYSQL_PATH=$MYSQL_ROOT/mysqldb |
164 |
+ |
MYSQL_SOCK=$MYSQL_PATH/mysql.sock |
165 |
+ |
MYSQL_PID=$MYSQL_PATH/mysqld.pid |
166 |
+ |
MYSQL_ERR=$MYSQL_PATH/error.log |
167 |
+ |
# grant permissions to CMS MySQL DBS account |
168 |
+ |
echo "+++ Grand permission to dbs account, DBS schema %{dbs_version} ..." |
169 |
+ |
#echo "$MYSQL_ROOT/bin/mysql -udbs -pcmsdbs --socket=$MYSQL_SOCK" |
170 |
+ |
echo "$DBS_SCHEMA_ROOT/lib/Schema/NeXtGen/DBS-NeXtGen-MySQL_DEPLOYABLE.sql" |
171 |
+ |
# DBS uses trigger which requires to have SUPER priveleges, so we'll create DB using root |
172 |
+ |
# and delegate this to dbs account. |
173 |
+ |
export DBS_SCHEMA=`grep "^use " $DBS_SCHEMA_ROOT/lib/Schema/NeXtGen/DBS-NeXtGen-MySQL_DEPLOYABLE.sql | awk '{print $2}' | sed "s/;//g"` |
174 |
+ |
|
175 |
+ |
# check existing DBS installation |
176 |
+ |
old=`mysql --vertical -uroot -pcms --port=$MYSQL_PORT --socket=$MYSQL_SOCK -e "show databases" | grep "Database:" | egrep "^CMS_DBS$" | awk '{print $2}'` |
177 |
+ |
if [ ! -z "$old" ]; then |
178 |
+ |
# we need to do upgrade, first let's move existing CMS_DBS |
179 |
+ |
cp -r $MYSQL_ROOT/var/db/mysql/CMS_DBS $MYSQL_ROOT/var/db/mysql/CMS_DBS_$old |
180 |
+ |
while true; do |
181 |
+ |
ver=`mysql --vertical -uroot -pcms --port=$MYSQL_PORT --socket=$MYSQL_SOCK -e "select SchemaVersion from SchemaVersion" CMS_DBS | grep SchemaVersion | awk '{print $2}'` |
182 |
+ |
if [ -f $DBS_SCHEMA_ROOT/lib/Schema/NeXtGen/upgrade.$ver ]; then |
183 |
+ |
$MYSQL_ROOT/bin/mysql -uroot -pcms --port=$MYSQL_PORT --socket=$MYSQL_SOCK < $DBS_SCHEMA_ROOT/lib/Schema/NeXtGen/upgrade.$ver |
184 |
+ |
else |
185 |
+ |
break |
186 |
+ |
fi |
187 |
+ |
done |
188 |
+ |
else |
189 |
+ |
# we will install fresh DBS |
190 |
+ |
$MYSQL_ROOT/bin/mysql -uroot -pcms --port=$MYSQL_PORT --socket=$MYSQL_SOCK < $DBS_SCHEMA_ROOT/lib/Schema/NeXtGen/DBS-NeXtGen-MySQL_DEPLOYABLE.sql |
191 |
+ |
$MYSQL_ROOT/bin/mysql --socket=$MYSQL_SOCK --port=$MYSQL_PORT -uroot -pcms mysql -e "GRANT ALL ON ${DBS_SCHEMA}.* TO dbs@localhost;" |
192 |
+ |
fi |
193 |
+ |
|
194 |
+ |
# I need to copy/deploy DBS.war file into tomcat area |
195 |
+ |
cp $DBS_SERVER_ROOT/Servers/JavaServer/DBS.war $APACHE_TOMCAT_ROOT/webapps |
196 |
+ |
|
197 |
+ |
# Copy mysql jdbc driver to tomcat |
198 |
+ |
cp -f $DBS_LIBS_ROOT/lib/*.jar $APACHE_TOMCAT_ROOT/common/lib |
199 |
+ |
|
200 |
+ |
# Fix path in dbs_init.sh file since now we know install area |
201 |
+ |
cat $DBS_SERVER_ROOT/Servers/JavaServer/bin/dbs_init.sh | sed "s,rpm_install_area,$RPM_INSTALL_PREFIX,g" > \ |
202 |
+ |
$DBS_SERVER_ROOT/Servers/JavaServer/bin/dbs_init.sh.new |
203 |
+ |
/bin/mv -f $DBS_SERVER_ROOT/Servers/JavaServer/bin/dbs_init.sh.new $DBS_SERVER_ROOT/Servers/JavaServer/bin/dbs_init.sh |
204 |
+ |
echo "+++ Fix path in dbs_init.sh" |
205 |
+ |
chmod a+x $DBS_SERVER_ROOT/Servers/JavaServer/bin/dbs_init.sh |
206 |
+ |
|
207 |
+ |
# time to start up tomcat for user |
208 |
+ |
#$APACHE_TOMCAT_ROOT/bin/catalina.sh start |
209 |
+ |
|
210 |
+ |
# kill running mysql|tomcat under my account since build is over |
211 |
+ |
echo "+++ Clean-up mysqld|tomcat processes" |
212 |
+ |
#ps -w -w -f -u`whoami` | egrep "mysqld|tomcat" | grep -v egrep | awk '{print "kill -9 "$2""}' |
213 |
+ |
#ps -w -w -f -u`whoami` | egrep "mysqld|tomcat" | grep -v egrep | awk '{print "kill -9 "$2""}' |/bin/sh |
214 |
+ |
#killall -q mysqld |
215 |
+ |
#cat $MYSQL_ROOT/mysqldb/mysqld.pid |
216 |
+ |
$MYSQL_ROOT/bin/mysqladmin -uroot -pcms --socket=$MYSQL_SOCK --port=$MYSQL_PORT shutdown |
217 |
+ |
killall -q tomcat |
218 |
+ |
|
219 |
+ |
# made correct link to LibValut |
220 |
+ |
rm -f $DBS_SERVER_ROOT/LibValut |
221 |
+ |
ln -s $DBS_LIBS_ROOT/lib $DBS_SERVER_ROOT/LibValut |
222 |
+ |
|
223 |
+ |
echo |
224 |
+ |
echo |
225 |
+ |
echo "##### IMPORTANT!!! #####" |
226 |
+ |
echo "To work with DBS you need to source init.sh file located at" |
227 |
+ |
echo "$DBS_SERVER_ROOT/etc/profile.d/init.sh" |
228 |
+ |
echo |
229 |
+ |
echo "OR use init script to start|stop|status DBS services:" |
230 |
+ |
echo "$DBS_SERVER_ROOT/Servers/JavaServer/bin/dbs_init.sh" |
231 |
+ |
echo "init script file can be placed into /etc/init.d/ to allow auto-startup of DBS service" |
232 |
+ |
echo "##########################" |
233 |
+ |
echo |
234 |
+ |
|