-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·84 lines (74 loc) · 2.36 KB
/
setup.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
#
#
#
echo "==> Installing software (if needed, may take few minutes)..."
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 > /dev/null 2>&1
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list > /dev/null
sudo apt-get -qq update
sudo apt-get -qq -y install \
haproxy \
mongodb-org \
jq
#
#
#
echo "==> Stopping MongoDB-HA..."
sudo systemctl stop mongod.service 2>/dev/null
sudo systemctl disable mongod.service 2>/dev/null
sudo systemctl stop haproxy mongodb-arbiter mongodb-27017 mongodb-27018 2>/dev/null
#
#
#
echo "==> Setting up MongoDB-HA..."
sudo cp -f /vagrant/hosts.conf /etc/hosts
sudo cp -f /vagrant/mongodb-arbiter.service /etc/systemd/system/mongodb-arbiter.service
sudo cp -f /vagrant/mongodb-27017.service /etc/systemd/system/mongodb-27017.service
sudo cp -f /vagrant/mongodb-27018.service /etc/systemd/system/mongodb-27018.service
sudo systemctl daemon-reload
sudo mkdir -p /data/mongodb-farm
sudo rm -rf /data/mongodb-farm/*
sudo mkdir -p /data/mongodb-farm/27017
sudo mkdir -p /data/mongodb-farm/27018
sudo mkdir -p /data/mongodb-farm/arbiter
sudo cp -f /vagrant/mongodb-27017.conf /data/mongodb-farm/mongodb-27017.conf
sudo cp -f /vagrant/mongodb-27018.conf /data/mongodb-farm/mongodb-27018.conf
sudo cp -f /vagrant/mongodb-arbiter.conf /data/mongodb-farm/mongodb-arbiter.conf
sudo chown -R vagrant:vagrant /data/mongodb-farm
sudo mkdir -p /data/haproxy
sudo cp -f /vagrant/haproxy.conf /etc/haproxy/haproxy.cfg
#
#
#
echo "==> Starting MongoDB-HA services..."
sudo systemctl start \
haproxy \
mongodb-27017 \
mongodb-27018 \
mongodb-arbiter
#
#
#
echo "==> Initializing MongoDB-HA..."
SOCKET_STATUS="1"
while [ "${SOCKET_STATUS}" != "0" ]
do
echo "*** MongoDB-HA startup is in progress, please wait..."
nc -z -w2 127.0.0.1 27017
SOCKET_STATUS=$?
sleep 1
done
echo "==> MongoDB-HA startup is complete, initializing replication..."
mongo --quiet --port 27017 < /vagrant/rs0-initialize.js > /dev/null
#
#
#
echo "==> Waiting MongoDB-HA replication setup..."
IS_MASTER="false"
while [ "${IS_MASTER}" != "true" ]
do
echo "*** Replication setup is in progress, please wait..."
IS_MASTER=$(mongo --quiet --port 27017 --eval "JSON.stringify(db.isMaster())" | jq '.ismaster')
sleep 1
done
echo "==> Done!"