-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.sh
executable file
·151 lines (120 loc) · 4.01 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
#
# Instructions:
# From your vm wget this file.
# o wget https://github.com/dtest/plam16-proxysql/blob/master/setup.sh
# o chmod 755 setup.sh
# o ./setup.sh
#
# Misc:
# To remove all containers
# cd <the plam dir>
# docker-compose stop && docker-compose rm -vf # kills the containers
#
CWD=$(pwd)
PLAM_DIR="plam16-proxysql"
ANSIBLE_DIR="proxysql_ansible_modules"
DATE=$(date +"%s")
LOG_FILE="setup_${DATE}.log"
if [ ! -e ${PLAM_DIR} ] || [ ! -e ${ANSIBLE_DIR} ];then
echo "Updating apt"
echo
sudo apt-get update
echo
echo "Installing git"
echo
sudo apt-get -y install git
echo
echo "Cloning plam16-proxysql repo"
echo
git clone https://github.com/dtest/${PLAM_DIR}.git
echo
echo "Cloning Proxysql_ansible_modules repo"
echo
git clone https://github.com/bmildren/${ANSIBLE_DIR}.git
echo
echo "Linking in ${ANSIBLE_DIR}"
echo
ln -s ${CWD}/${ANSIBLE_DIR} ${CWD}/${PLAM_DIR}/ansible/library
echo
# echo "Getting sakila database."
# echo
# wget http://downloads.mysql.com/docs/sakila-db.tar.gz
# echo
fi
echo "Confirmed ${PLAM_DIR} and ${ANSIBLE_DIR} exist."
echo
echo
if [ $(grep docker /etc/group |wc -l) -lt 1 ];then
sudo groupadd docker
sudo usermod -aG docker $USER
echo
echo "========================================================================"
echo "Permissions need updating. Will exit in 5s for changes to take effect"
echo "Log back in and re-run script to continue."
echo "========================================================================"
echo
echo "Sleeping 5 before exiting."
sleep 5
kill -HUP $PPID
fi
echo "Confirmed permissions. Continuing"
echo
sleep 1
if [ $(dpkg -l |grep python |grep pip| wc -l) -lt 1 ];then
exec > >(tee ${LOG_FILE}) 2>&1
echo "============================================="
echo "Running everything required to install docker"
echo "============================================="
echo
# From: https://docs.docker.com/engine/installation/linux/ubuntulinux/
sudo apt-get install apt-transport-https ca-certificates
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo sh -c 'echo deb https://apt.dockerproject.org/repo ubuntu-trusty main > /etc/apt/sources.list.d/docker.list'
sudo apt-get update
sudo apt-get purge lxc-docker
apt-cache policy docker-engine
sudo apt-get -y install linux-image-extra-$(uname -r) linux-image-extra-virtual
sudo apt-get -y install docker-engine
sudo service docker start
sudo docker run hello-world
echo "============================================="
echo "Installing pip, ansible, git, etc"
echo "============================================="
echo
sudo apt-get -y install python-pip
# Both markupsafe and python-dev appear to be required by ansible
sudo pip install markupsafe
sudo apt-get -y install python-dev
sudo pip install ansible
sudo apt-get -y install git
#
sudo pip install docker-compose
echo
echo
echo "=================================================="
echo "Prep completed"
echo "=================================================="
fi
if [ $(docker ps |grep -v CONTAINER |wc -l) -lt 4 ] || [ $(docker ps |grep master |wc -l) -lt 1 ];then
echo "=================================================="
echo "Setting up docker containers"
echo "=================================================="
echo
sleep 5
cd ${PLAM_DIR}
time docker-compose up -d
echo "Giving time for containers to start; sleeping..." && sleep 50
cd ansible && time ansible-playbook -i inventory setup.yml
fi
# echo
# echo "Sleeping 5s to ensure master container is ready for sakila"
# echo
# sleep 5
# if [ $(docker ps |grep master |wc -l) -gt 0 ];then
# echo "Copying sakila db to master container."
# echo
# docker cp ${CWD}/sakila-db.tar.gz master:/var/tmp
# echo
# fi
cd $CWD