|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | 3 | # Script which installs versions of MongoDB specified using an environment variable |
4 | | - |
5 | | -if [ ! "${MONGODB}" ]; then |
6 | | - echo "MONGODB environment variable not set" |
| 4 | +if [ ! "${MONGODB_VERSION}" ]; then |
| 5 | + echo "MONGODB_VERSION environment variable not set." |
7 | 6 | exit 2 |
8 | 7 | fi |
9 | 8 |
|
10 | 9 | # Note: MongoDB 2.4 and 2.6 don't work with ramdisk since they don't work with |
11 | 10 | # small files and require at least 3 GB of space |
12 | | -if [ ${MONGODB} = '2.4.9' ] || [ ${MONGODB} = '2.6.12' ]; then |
| 11 | +if [ "${MONGODB_VERSION}" = '2.4.9' ] || [ "${MONGODB_VERSION}" = '2.6.12' ]; then |
13 | 12 | DATA_DIR=/tmp/mongodbdata |
14 | 13 | else |
15 | 14 | DATA_DIR=/mnt/ramdisk/mongodb |
16 | 15 | fi |
17 | 16 |
|
18 | | -wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${MONGODB}.tgz -O /tmp/mongodb.tgz |
19 | | -tar -xvf /tmp/mongodb.tgz |
| 17 | +DATA_DIR=/tmp/mongodbdata |
| 18 | +MONGODB_DIR=/tmp/mongodb |
| 19 | + |
20 | 20 | mkdir -p ${DATA_DIR} |
21 | | -echo "Starting MongoDB v${MONGODB}" |
22 | | -${PWD}/mongodb-linux-x86_64-${MONGODB}/bin/mongod --nojournal --journalCommitInterval 500 \ |
23 | | - --syncdelay 0 --dbpath ${DATA_DIR} --bind_ip 127.0.0.1 &> /tmp/mongodb.log & |
24 | | -EXIT_CODE=$? |
| 21 | +mkdir -p ${MONGODB_DIR} |
| 22 | + |
| 23 | +DOWNLOAD_URL="http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${MONGODB_VERSION}.tgz" |
| 24 | + |
| 25 | +echo "Downloading MongoDB ${MONGODB_VERSION} from ${DOWNLOAD_URL}" |
| 26 | +wget -q ${DOWNLOAD_URL} -O /tmp/mongodb.tgz |
| 27 | +tar -xvf /tmp/mongodb.tgz -C ${MONGODB_DIR} --strip=1 |
| 28 | + |
| 29 | +echo "Symlinking mongo shell binary to /usr/local/bin" |
| 30 | + |
| 31 | +# Symlink latest mongodb shell |
| 32 | +sudo ln -sf ${MONGODB_DIR}/bin/mongo /usr/local/bin/mongo |
| 33 | +sudo ln -sf ${MONGODB_DIR}/bin/mongo /usr/bin/mongo |
| 34 | + |
| 35 | +echo "Starting MongoDB v${MONGODB_VERSION}" |
| 36 | +# Note: We use --notablescan option to detected missing indexes early. When this |
| 37 | +# option is enabled, queries which result in table scan (which usually means a |
| 38 | +# missing index or a bad query) are not allowed and result in a failed test. |
| 39 | +#--wiredTigerStatisticsLogDelaySecs 0 --noIndexBuildRetry --noscripting --notablescan \ |
| 40 | +${MONGODB_DIR}/bin/mongod --nojournal --journalCommitInterval 500 --syncdelay 0 \ |
| 41 | + --wiredTigerStatisticsLogDelaySecs 0 --noIndexBuildRetry --noscripting \ |
| 42 | + --dbpath ${DATA_DIR} --bind_ip 127.0.0.1 &> /tmp/mongodb.log & |
| 43 | +MONGODB_PID=$! |
| 44 | + |
| 45 | +# Give process some time to start up |
25 | 46 | sleep 5 |
26 | 47 |
|
27 | | -if [ ${EXIT_CODE} -ne 0 ]; then |
| 48 | +if ps -p ${MONGODB_PID} > /dev/null; then |
| 49 | + echo "MongoDB successfuly started" |
| 50 | + tail -30 /tmp/mongodb.log |
| 51 | + exit 0 |
| 52 | +else |
28 | 53 | echo "Failed to start MongoDB" |
29 | 54 | tail -30 /tmp/mongodb.log |
30 | 55 | exit 1 |
31 | 56 | fi |
32 | | - |
33 | | -tail -30 /tmp/mongodb.log |
|
0 commit comments