forked from cloudify-cosmo/cloudify-nodecellar-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-mongo.sh
More file actions
executable file
·68 lines (53 loc) · 2.04 KB
/
Copy pathstart-mongo.sh
File metadata and controls
executable file
·68 lines (53 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
function info(){ builtin echo [INFO] [$(basename $0)] $@; }
function error(){ builtin echo [ERROR] [$(basename $0)] $@; }
#. ${CLOUDIFY_LOGGING}
#. ${CLOUDIFY_FILE_SERVER}
TEMP_DIR="/tmp"
MONGO_ROOT=${TEMP_DIR}/mongodb
PID_FILE="mongo.pid"
info "Changing directory to ${MONGO_ROOT}"
cd ${MONGO_ROOT} || exit $?
info "Starting mongodb from ${MONGO_ROOT}/mongodb/bin/mongod with port ${port}"
nohup ./mongodb/bin/mongod --port ${port} --dbpath data --rest --journal --shardsvr > /dev/null 2>&1 &
echo $! > ${PID_FILE}
info "Waiting for mongo to launch"
STARTED=false
REST_PORT=`expr ${port} + 1000`
for i in $(seq 1 120)
do
if wget http://localhost:${REST_PORT} 2>/dev/null ; then
info "Server is up."
STARTED=true
break
else
info "mongodb not up. waiting 1 second."
sleep 1
fi
done
if [ ${STARTED} = false ]; then
error "Failed to start mongodb in 120 seconds."
exit 1
fi
# Installing jq to parse json
info "Installing jq"
if [ ! -f ./jq ]; then
wget http://stedolan.github.io/jq/download/linux64/jq || exit $?
chmod +x ./jq || exit $?
info "jq installed sucessfully"
else
info "Skipping, jq already installed"
fi
info "Getting latest state version of current node ${CLOUDIFY_NODE_ID} from cloudify manager at ${CLOUDIFY_MANAGER_IP}"
NODE_STATE=`curl -s -X GET "http://${CLOUDIFY_MANAGER_IP}:80/node-instances/${CLOUDIFY_NODE_ID}"`
info "Node state is ${NODE_STATE}"
VERSION=`echo ${NODE_STATE} | ./jq '.version'`
info "version is ${VERSION}"
IP_ADDR=$(ip addr | grep inet | grep eth0 | awk -F" " '{print $2}'| sed -e 's/\/.*$//')
info "About to post IP address ${IP_ADDR} and port ${port}"
RUNTIME_PROPERTIES="{\"runtime_properties\": {\"ip_address\": \"${IP_ADDR}\", \"port\":\"${port}\"}, \"version\": ${VERSION}}"
URL="http://${CLOUDIFY_MANAGER_IP}:80/node-instances/${CLOUDIFY_NODE_ID}"
info "Runtime properties: ${RUNTIME_PROPERTIES}"
info "Url: ${URL}"
curl -X PATCH -H "Content-Type: application/json" -d "${RUNTIME_PROPERTIES}" ${URL}
info "Successfully posted data to manager"