(travis) Properly diagnose potential OOM in 50_after_success.bash
[dbsrgits/DBIx-Class.git] / maint / travis-ci_scripts / 10_before_install.bash
CommitLineData
b58ecb01 1#!/bin/bash
2
01fd95b6 3export SHORT_CIRCUIT_SMOKE
4
36372426 5if have_sudo ; then
6
7 # Stop pre-started RDBMS, move their data back to disk (save RAM)
8 # sync for some settle time (not available on all platforms)
9 for d in mysql postgresql ; do
10 # maybe not even running
11 run_or_err "Stopping $d" "sudo /etc/init.d/$d stop || /bin/true"
12
13 # no longer available on newer build systems
14 if [[ -d /var/ramfs/$d ]] ; then
15 sudo rm -rf /var/lib/$d
16 sudo mv /var/ramfs/$d /var/lib/
17 sudo ln -s /var/lib/$d /var/ramfs/$d
18 fi
19 done
20 /bin/sync
21fi
06278456 22
fcdd56ca 23# Sanity check VM before continuing
24echo "
25=============================================================================
26
27= Startup Meminfo
28$(free -m -t)
29
30============================================================================="
31
32CI_VM_MIN_FREE_MB=2000
33if [[ "$(free -m | grep 'buffers/cache:' | perl -p -e '$_ = (split /\s+/, $_)[3]')" -lt "$CI_VM_MIN_FREE_MB" ]]; then
34 SHORT_CIRCUIT_SMOKE=1
35 echo_err "
36=============================================================================
37
38CI virtual machine stuck in a state with a lot of memory locked for no reason.
39Under Travis this state usually results in a failed build.
40Short-circuiting buildjob to avoid false negatives, please restart it manually.
41
42============================================================================="
01fd95b6 43
44# pull requests are always scrutinized after the fact anyway - run a
45# a simpler matrix
46elif [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then
47 if [[ -n "$BREWVER" ]]; then
48 # just don't brew anything
49 SHORT_CIRCUIT_SMOKE=1
50 else
51 # running PRs with 1 thread is non-sensical
52 VCPU_USE=""
53 fi
fcdd56ca 54fi
55
b58ecb01 56if [[ -n "$SHORT_CIRCUIT_SMOKE" ]] ; then return ; fi
57
36372426 58# Previously we were going off the OpenVZ vcpu count and dividing by 3
59# With the new infrastructure, somply go with "something high"
60export VCPU_AVAILABLE=10
5ac4a96d 61
62if [[ -z "$VCPU_USE" ]] ; then
63 export VCPU_USE="$VCPU_AVAILABLE"
2a89732d 64fi
003e97c5 65
003e97c5 66
36372426 67if [[ "$CLEANTEST" != "true" ]]; then
b58ecb01 68
36372426 69 if [[ -z "$(tail -n +2 /proc/swaps)" ]] ; then
70 run_or_err "Configuring swap (for Oracle)" \
71 "sudo bash -c 'dd if=/dev/zero of=/swap.img bs=256M count=5 && chmod 600 /swap.img && mkswap /swap.img && swapon /swap.img'"
72 fi
e861e4f0 73
538c5c46 74
75 # never installed, this looks like trusty
76 if [[ ! -d /var/lib/mysql ]] ; then
77 sudo dpkg --add-architecture i386
78 extra_debs+=( postgresql mysql-server )
79 fi
80
81
82 # these APT sources do not mean anything to us anyway
83 sudo rm -rf /etc/apt/sources.list.d/*
1e735709 84
b58ecb01 85 #
538c5c46 86 # FIXME these debconf lines should automate the firebird config but seem not to :(((
b58ecb01 87 sudo bash -c 'echo -e "firebird2.5-super\tshared/firebird/enabled\tboolean\ttrue" | debconf-set-selections'
88 sudo bash -c 'echo -e "firebird2.5-super\tshared/firebird/sysdba_password/new_password\tpassword\t123" | debconf-set-selections'
89
538c5c46 90 run_or_err "Updating APT sources" "sudo apt-get update"
91 apt_install ${extra_debs[@]} libmysqlclient-dev memcached firebird2.5-super firebird2.5-dev expect
d50f2fe1 92
7a96e0d6 93
538c5c46 94 # need to stop them again, in case we installed them above (trusty)
95 for d in mysql postgresql ; do
96 run_or_err "Stopping $d" "sudo /etc/init.d/$d stop || /bin/true"
97 done
98
99
100 export CACHE_DIR="/tmp/poormanscache"
101 mkdir "$CACHE_DIR"
7a96e0d6 102
103 # FIXME - by default db2 eats too much memory, we won't be able to test on legacy infra
104 # someone needs to add a minimizing configuration akin to 9367d187
105 if [[ "$(free -m | grep 'Mem:' | perl -p -e '$_ = (split /\s+/, $_)[1]')" -gt 4000 ]] ; then
538c5c46 106 run_or_err "Getting DB2 from poor man's cache github" '
107 wget -qO- https://github.com/poormanscache/poormanscache/archive/DB2_ExC/9.7.5_deb_x86-64.tar.gz \
108 | tar -C "$CACHE_DIR" -zx'
109
110 # the actual package is built for lucid, installs fine on both precise and trusty
111 manual_debs+=( "db2exc_9.7.5-0lucid0_amd64.deb" )
36372426 112 fi
113
538c5c46 114 run_or_err "Getting Oracle from poor man's cache github" '
115 wget -qO- https://github.com/poormanscache/poormanscache/archive/OracleXE/10.2.0_deb_mixed.tar.gz \
116 | tar -C "$CACHE_DIR" -zx'
117 manual_debs+=( "bc-multiarch-travis_1.0_all.deb" "oracle-xe_10.2.0.1-1.1_i386.deb" )
118
119
120 # reassemble chunked pieces ( working around github's filesize limit )
121 for reass in $CACHE_DIR/*/reassemble ; do /bin/bash "$reass" ; done
122
123 run_or_err "Installing RDBMS debs manually: $( echo ${manual_debs[@]/#/$CACHE_DIR/*/*/} )" \
124 "sudo dpkg -i $( echo ${manual_debs[@]/#/$CACHE_DIR/*/*/} ) || sudo bash -c 'source maint/travis-ci_scripts/common.bash && apt_install -f'"
003e97c5 125
36372426 126
7a96e0d6 127 # needs to happen separately and *after* db2exc, as the former shits all over /usr/include (wtf?!)
128 # for more info look at /opt/ibm/db2/V9.7/instance/db2iutil :: create_links()
129 apt_install unixodbc-dev
130
b58ecb01 131
132### config memcached
106c81a5 133 run_or_err "Starting memcached" "sudo /etc/init.d/memcached start"
b58ecb01 134 export DBICTEST_MEMCACHED=127.0.0.1:11211
135
136### config mysql
3c26d329 137 run_or_err "Installing minimizing MySQL config" "\
138 sudo bash -c 'rm /var/lib/mysql/ib*' \
139 && sudo cp maint/travis-ci_scripts/configs/minimal_mysql_travis.cnf /etc/mysql/conf.d/ \
140 && sudo chmod 644 /etc/mysql/conf.d/*.cnf \
141 "
142
fcdd56ca 143 run_or_err "Starting MySQL" "sudo /etc/init.d/mysql start"
36372426 144 run_or_err "Creating MySQL TestDB" "mysql -u root -e 'create database dbic_test;'"
b58ecb01 145 export DBICTEST_MYSQL_DSN='dbi:mysql:database=dbic_test;host=127.0.0.1'
146 export DBICTEST_MYSQL_USER=root
147
148### config pg
fcdd56ca 149 run_or_err "Starting PostgreSQL" "sudo /etc/init.d/postgresql start"
b58ecb01 150 run_or_err "Creating PostgreSQL TestDB" "psql -c 'create database dbic_test;' -U postgres"
151 export DBICTEST_PG_DSN='dbi:Pg:database=dbic_test;host=127.0.0.1'
152 export DBICTEST_PG_USER=postgres
153
154### conig firebird
155 # poor man's deb config
156 EXPECT_FB_SCRIPT='
157 spawn dpkg-reconfigure --frontend=text firebird2.5-super
158 expect "Enable Firebird server?"
159 send "\177\177\177\177yes\r"
160 expect "Password for SYSDBA"
161 send "123\r"
2c649faf 162 sleep 2
003e97c5 163 expect eof
b58ecb01 164 '
b58ecb01 165 # creating testdb
166 # FIXME - this step still fails from time to time >:(((
167 # has to do with the FB reconfiguration I suppose
906c0355 168 # for now if it fails twice - simply skip FB testing
2c649faf 169 for i in 1 2 3 ; do
906c0355 170
171 run_or_err "Re-configuring Firebird" "
172 sync
2c649faf 173 sleep 5
906c0355 174 DEBIAN_FRONTEND=text sudo expect -c '$EXPECT_FB_SCRIPT'
906c0355 175 "
176
177 if run_or_err "Creating Firebird TestDB" \
178 "echo \"CREATE DATABASE '/var/lib/firebird/2.5/data/dbic_test.fdb';\" | sudo isql-fb -u sysdba -p 123"
179 then
da59679a 180
137dca08 181 run_or_err "Fetching and building Firebird ODBC driver" '
182 cd "$(mktemp -d)"
183 wget -qO- http://sourceforge.net/projects/firebird/files/firebird-ODBC-driver/2.0.2-Release/OdbcFb-Source-2.0.2.153.gz/download | tar -zx
184 cd Builds/Gcc.lin
185 perl -p -i -e "s|/usr/lib64|/usr/lib/x86_64-linux-gnu|g" ../makefile.environ
186 make -f makefile.linux
187 sudo make -f makefile.linux install
188 '
189
190 sudo bash -c 'cat >> /etc/odbcinst.ini' <<< "
191[Firebird]
192Description = InterBase/Firebird ODBC Driver
193Driver = /usr/lib/x86_64-linux-gnu/libOdbcFb.so
194Setup = /usr/lib/x86_64-linux-gnu/libOdbcFb.so
195Threading = 1
196FileUsage = 1
197"
198
906c0355 199 export DBICTEST_FIREBIRD_DSN=dbi:Firebird:dbname=/var/lib/firebird/2.5/data/dbic_test.fdb
200 export DBICTEST_FIREBIRD_USER=SYSDBA
201 export DBICTEST_FIREBIRD_PASS=123
202
203 export DBICTEST_FIREBIRD_INTERBASE_DSN=dbi:InterBase:dbname=/var/lib/firebird/2.5/data/dbic_test.fdb
204 export DBICTEST_FIREBIRD_INTERBASE_USER=SYSDBA
205 export DBICTEST_FIREBIRD_INTERBASE_PASS=123
206
137dca08 207 export DBICTEST_FIREBIRD_ODBC_DSN="dbi:ODBC:Driver=Firebird;Dbname=/var/lib/firebird/2.5/data/dbic_test.fdb"
208 export DBICTEST_FIREBIRD_ODBC_USER=SYSDBA
209 export DBICTEST_FIREBIRD_ODBC_PASS=123
210
906c0355 211 break
212 fi
213
214 done
b58ecb01 215
003e97c5 216### config oracle
fa7907b0 217 SRV_ORA_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
218
219 # without this some of the more zealous tests can exhaust the amount
220 # of listeners and oracle is too slow to spin extras up :(
221 sudo bash -c "echo -e '\nprocesses=150' >> $SRV_ORA_HOME/config/scripts/init.ora"
222
003e97c5 223 EXPECT_ORA_SCRIPT='
224 spawn /etc/init.d/oracle-xe configure
225
226 sleep 1
227 set send_slow {1 .005}
228
229 expect "Specify the HTTP port that will be used for Oracle Application Express"
230 sleep 0.5
231 send -s "8021\r"
232
233 expect "Specify a port that will be used for the database listener"
234 sleep 0.5
235 send -s "1521\r"
236
237 expect "Specify a password to be used for database accounts"
238 sleep 0.5
239 send -s "adminpass\r"
240
241 expect "Confirm the password"
242 sleep 0.5
243 send -s "adminpass\r"
244
245 expect "Do you want Oracle Database 10g Express Edition to be started on boot"
246 sleep 0.5
247 send -s "n\r"
248
249 sleep 0.5
250 expect "Configuring Database"
251
252 sleep 1
253 expect eof
254 wait
255 '
256
257 # if we do not redirect to some random file, but instead try to capture
258 # into a var the way run_or_err does - everything hangs
259 # FIXME: I couldn't figure it out after 3 hours of headdesking,
260 # would be nice to know the reason eventually
261 run_or_err "Configuring OracleXE" "sudo $(which expect) -c '$EXPECT_ORA_SCRIPT' &>/tmp/ora_configure_10.2.log"
003e97c5 262
263 export DBICTEST_ORA_DSN=dbi:Oracle://localhost:1521/XE
264 export DBICTEST_ORA_USER=dbic_test
265 export DBICTEST_ORA_PASS=abc123456
fa7907b0 266 export DBICTEST_ORA_EXTRAUSER_DSN="$DBICTEST_ORA_DSN"
003e97c5 267 export DBICTEST_ORA_EXTRAUSER_USER=dbic_test_extra
268 export DBICTEST_ORA_EXTRAUSER_PASS=abc123456
269
270 run_or_err "Create Oracle users" "ORACLE_SID=XE ORACLE_HOME=$SRV_ORA_HOME $SRV_ORA_HOME/bin/sqlplus -L -S system/adminpass @/dev/stdin <<< '
271 CREATE USER $DBICTEST_ORA_USER IDENTIFIED BY $DBICTEST_ORA_PASS;
272 GRANT connect,resource TO $DBICTEST_ORA_USER;
273 CREATE USER $DBICTEST_ORA_EXTRAUSER_USER IDENTIFIED BY $DBICTEST_ORA_EXTRAUSER_PASS;
274 GRANT connect,resource TO $DBICTEST_ORA_EXTRAUSER_USER;
275 '"
276
538c5c46 277 export ORACLE_HOME="$CACHE_DIR/poormanscache-OracleXE-10.2.0_deb_mixed/ora_instaclient/x86-64/oracle_instaclient_10.2.0.5.0"
7a96e0d6 278
279### config db2exc
280 # we may have skipped installation due to low memory
281 if dpkg -l db2exc &>/dev/null ; then
282 # WTF is this world-writable?
283 # Strip the write bit so it doesn't trip Ubuntu's symlink-in-/tmp attack mitigation
284 sudo chmod -R o-w ~dasusr1/das
285
286 export DB2_HOME=/opt/ibm/db2/V9.7
287 export DBICTEST_DB2_DSN=dbi:DB2:DATABASE=dbictest
288 export DBICTEST_DB2_USER=db2inst1
289 export DBICTEST_DB2_PASS=abc123456
290
291 run_or_err "Set up DB2 users" \
292 "echo -e '$DBICTEST_DB2_PASS\n$DBICTEST_DB2_PASS' | sudo passwd $DBICTEST_DB2_USER"
293
294 run_or_err "Create DB2 database" \
295 "sudo -u $DBICTEST_DB2_USER -i db2 'CREATE DATABASE dbictest' && sudo -u $DBICTEST_DB2_USER -i db2 'ACTIVATE DATABASE dbictest'"
296 fi
297
b58ecb01 298fi