1#!/bin/sh
2set -o xtrace   # Write all commands first to stderr
3set -o errexit  # Exit the script with error if any of the commands fail
4
5DIR=$(dirname $0)
6# Functions to fetch MongoDB binaries
7. $DIR/download-mongodb.sh
8
9get_distro
10get_mongodb_download_url_for "$DISTRO" "$MONGODB_VERSION"
11download_and_extract "$MONGODB_DOWNLOAD_URL" "$EXTRACT"
12
13
14OS=$(uname -s | tr '[:upper:]' '[:lower:]')
15
16AUTH=${AUTH:-noauth}
17SSL=${SSL:-nossl}
18TOPOLOGY=${TOPOLOGY:-server}
19
20case "$OS" in
21   cygwin*)
22      export MONGO_ORCHESTRATION_HOME="c:/data/MO"
23      ;;
24   *)
25      export MONGO_ORCHESTRATION_HOME=$(pwd)"/MO"
26      ;;
27esac
28rm -rf $MONGO_ORCHESTRATION_HOME
29mkdir -p $MONGO_ORCHESTRATION_HOME/lib
30mkdir -p $MONGO_ORCHESTRATION_HOME/db
31
32if [ -z $ORCHESTRATION_FILE ]; then
33   ORCHESTRATION_FILE="basic"
34fi
35if [ "$AUTH" = "auth" ]; then
36  ORCHESTRATION_FILE="auth"
37  MONGO_SHELL_CONNECTION_FLAGS="-ubob -ppwd123"
38fi
39
40if [ "$IPV4_ONLY" = "on" ]; then
41  ORCHESTRATION_FILE="${ORCHESTRATION_FILE}-ipv4-only"
42fi
43
44if [ "$SSL" != "nossl" ]; then
45   cp -f tests/x509gen/* $MONGO_ORCHESTRATION_HOME/lib/
46   # find print0 and xargs -0 not available on Solaris. Lets hope for good paths
47   find orchestration_configs -name \*.json | xargs perl -p -i -e "s|/tmp/orchestration-home|$MONGO_ORCHESTRATION_HOME/lib|g"
48   ORCHESTRATION_FILE="${ORCHESTRATION_FILE}-ssl"
49fi
50
51export ORCHESTRATION_FILE="orchestration_configs/${TOPOLOGY}s/${ORCHESTRATION_FILE}.json"
52export ORCHESTRATION_URL="http://localhost:8889/v1/${TOPOLOGY}s"
53
54export TMPDIR=$MONGO_ORCHESTRATION_HOME/db
55echo From shell `date` > $MONGO_ORCHESTRATION_HOME/server.log
56
57
58case "$OS" in
59   cygwin*)
60      # Python has problems with unix style paths in cygwin. Must use c:\\ paths
61      rm -rf /cygdrive/c/mongodb
62      cp -r mongodb /cygdrive/c/mongodb
63      echo "{ \"releases\": { \"default\": \"c:\\\\mongodb\\\\bin\" }}" > orchestration.config
64
65      # Make sure MO is running latest version
66      python.exe -m virtualenv venv
67      cd venv
68      . Scripts/activate
69      git clone https://github.com/10gen/mongo-orchestration.git
70      cd mongo-orchestration
71      pip install .
72      cd ../..
73      ls `pwd`/mongodb/bin/mongo* || true
74      nohup mongo-orchestration -f orchestration.config -e default --socket-timeout-ms=60000 --bind=127.0.0.1  --enable-majority-read-concern -s wsgiref start > $MONGO_ORCHESTRATION_HOME/out.log 2> $MONGO_ORCHESTRATION_HOME/err.log < /dev/null &
75      if [ "$SSL" != "nossl" ]; then
76         export MONGO_SHELL_CONNECTION_FLAGS="$MONGO_SHELL_CONNECTION_FLAGS --host localhost --ssl --sslCAFile=$MONGO_ORCHESTRATION_HOME/lib/ca.pem --sslPEMKeyFile=$MONGO_ORCHESTRATION_HOME/lib/client.pem"
77      fi
78      ;;
79   *)
80      echo "{ \"releases\": { \"default\": \"`pwd`/mongodb/bin\" } }" > orchestration.config
81      # Make sure MO is running latest version
82      python -m virtualenv venv
83      cd venv
84      . bin/activate
85      git clone https://github.com/10gen/mongo-orchestration.git
86      cd mongo-orchestration
87      # Our zSeries machines are static-provisioned, cache corruptions persist.
88      if [ $(uname -m) = "s390x" ]; then
89         echo "Disabling pip cache"
90         PIP_PARAM="--no-cache-dir"
91      fi
92      pip $PIP_PARAM install .
93      cd ../..
94      nohup mongo-orchestration -f orchestration.config -e default --socket-timeout-ms=60000 --bind=127.0.0.1  --enable-majority-read-concern start > $MONGO_ORCHESTRATION_HOME/out.log 2> $MONGO_ORCHESTRATION_HOME/err.log < /dev/null &
95      if [ "$SSL" != "nossl" ]; then
96         export MONGO_SHELL_CONNECTION_FLAGS="$MONGO_SHELL_CONNECTION_FLAGS --host localhost --ssl --sslCAFile=$MONGO_ORCHESTRATION_HOME/lib/ca.pem --sslPEMKeyFile=$MONGO_ORCHESTRATION_HOME/lib/client.pem"
97      fi
98      ;;
99esac
100
101sleep 15
102curl http://localhost:8889/ --silent --max-time 120 --fail
103
104sleep 5
105
106pwd
107curl --silent --data @"$ORCHESTRATION_FILE" "$ORCHESTRATION_URL" --max-time 300 --fail
108
109sleep 15
110
111`pwd`/mongodb/bin/mongo $MONGO_SHELL_CONNECTION_FLAGS --eval 'printjson(db.serverBuildInfo())' admin
112`pwd`/mongodb/bin/mongo $MONGO_SHELL_CONNECTION_FLAGS --eval 'printjson(db.isMaster())' admin
113