forked from waggle-sensor/beehive-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeehiveInstall.bash
213 lines (171 loc) · 5.5 KB
/
beehiveInstall.bash
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
# Must be run after superuser -i command:
### sudo -i
#####################################################################
######### UN-INSTALL old beehive server
#####################################################################
## files in $DATE=/mnt
rm -rf /mnt/cassandra /mnt/mysql /mnt/rabbitmq /mnt/ssh_keys /mnt/waggle
##-- systemd
cd /etc/systemd/system
systemctl stop beehive-*
systemctl disable beehive-*
rm -f /etc/systemd/system/beehive-*.service
systemctl status beehive-* --no-pager -l
systemctl list-units beehive-* --all
##-- docker containers
echo "BEFORE removal...."
docker ps
for container in `docker ps -q`;
do echo ' removing container ' $container
docker rm -fv $container
done
echo "AFTER removal...."
docker ps
service docker stop
echo "...."
#####################################################################
######### INSTALL
#####################################################################
apt-get install curl
#### Docker
apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
export CODENAME=$(lsb_release --codename | grep -o "[a-z]*$" | tr -d '\n')
echo "deb https://apt.dockerproject.org/repo ubuntu-${CODENAME} main" > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get install -y docker-engine
service docker restart
export DATA="/mnt"
echo "export DATA=/mnt/" >> ~/.bash_profile
docker network create beehive
docker network ls
docker network inspect beehive
### SSL
docker pull waggle/beehive-server:latest
[ ! -z "$DATA" ] && docker run -ti \
--name certs \
--rm \
-v ${DATA}/waggle/SSL/:/usr/lib/waggle/SSL/ \
waggle/beehive-server:latest ./SSL/create_certificate_authority.sh
### mysql
docker rm -f beehive-mysql
[ ! -z "$DATA" ] && \
docker run -d \
--name beehive-mysql \
--net beehive \
-v ${DATA}/mysql/datadir:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=waggle \
-e MYSQL_DATABASE=waggle \
-e MYSQL_USER=waggle \
-e MYSQL_PASSWORD=waggle \
mysql:5.7.10
sleep 20
while true
do curl https://raw.githubusercontent.com/waggle-sensor/beehive-server/master/beehive-mysql/tables.sql | docker exec -i beehive-mysql mysql -u waggle --password=waggle \
&& break
sleep 10
nTries=$[$nTries+1]
echo " mysql try #" $nTries " ..."
done
### Cassandra
[ ! -z "$DATA" ] && \
docker run -d \
--name beehive-cassandra \
--net beehive \
-v ${DATA}/cassandra/:/var/lib/cassandra/ \
--ulimit memlock=-1 \
--ulimit nofile=100000 \
--ulimit nproc=32768 \
--cap-add IPC_LOCK \
cassandra:3.2 -R
### RabbitMQ
mkdir -p ${DATA}/rabbitmq/config/ && \
curl https://raw.githubusercontent.com/waggle-sensor/beehive-server/master/beehive-rabbitmq/rabbitmq.config > ${DATA}/rabbitmq/config/rabbitmq.config
docker pull waggle/beehive-server:latest
[ ! -z "$DATA" ] && docker run -ti \
--name certs \
--rm \
-v ${DATA}/waggle/SSL/:/usr/lib/waggle/SSL/ \
waggle/beehive-server:latest ./SSL/create_server_cert.sh
chmod +x ${DATA}/waggle/SSL/server
docker rm -f beehive-rabbitmq
[ ! -z "$DATA" ] && docker run -d \
--hostname beehive-rabbitmq \
--name beehive-rabbitmq \
-e RABBITMQ_NODENAME=beehive-rabbitmq \
-v ${DATA}/rabbitmq/config/:/etc/rabbitmq:rw \
-v ${DATA}/rabbitmq/data/:/var/lib/rabbitmq/:rw \
-v ${DATA}/waggle/SSL:/usr/lib/waggle/SSL/:ro \
--expose=23181 \
-p 23181:23181 \
--net beehive \
rabbitmq:3.5.6
#sleep 10 # TODO: give rabbit container a chance to come up, TODO: fix hack with something more rigorous - eg. poll for service
nTries=0
sleep 20
while true
do docker exec -ti beehive-rabbitmq bash -c '\
rabbitmqctl add_user node waggle ; \
rabbitmqctl add_user server waggle ; \
rabbitmqctl set_permissions node "node_.*" ".*" ".*" ; \
rabbitmqctl set_permissions server ".*" ".*" ".*" ; \
rabbitmq-plugins enable rabbitmq_auth_mechanism_ssl' \
&& break
sleep 10
nTries=$[$nTries+1]
echo "rabbitmqctl try #" $nTries " ..."
done
docker logs beehive-rabbitmq
### Beehive Server (with Docker)
docker pull waggle/beehive-server:latest
[ ! -z "$DATA" ] && docker run -ti \
--name certs \
--rm \
-v ${DATA}/waggle/SSL/:/usr/lib/waggle/SSL/ \
waggle/beehive-server:latest ./SSL/create_client_cert.sh server beehive-server
###--- Starting the docker container
docker rm -f beehive-server
docker pull waggle/beehive-server
#docker run -ti --name beehive-server \
docker run -tid --name beehive-server \
--net beehive \
-v ${DATA}/waggle/SSL/:/usr/lib/waggle/SSL/ \
waggle/beehive-server:latest
docker exec beehive-server ls configure Server.py
docker exec beehive-server ./configure
docker exec -d beehive-server ./Server.py --logging
### nginx and systemd
cd ~
rm -rf git
mkdir -p git
cd git
git clone https://github.com/waggle-sensor/beehive-server.git
cd ~/git/beehive-server/
### nginx
docker rm -f beehive-nginx
docker rmi waggle/beehive-nginx
docker build -t waggle/beehive-nginx ~/git/beehive-server/beehive-nginx/
[ ! -z "$DATA" ] && \
docker run \
-d \
--name=beehive-nginx \
--net beehive \
-p 80:80 \
waggle/beehive-nginx /usr/sbin/nginx -g 'daemon off;'
### systemd
#cd ~
#rm -rf git
#mkdir -p git
#cd git
#git clone https://github.com/waggle-sensor/beehive-server.git
cd ~/git/beehive-server/systemd/
for service in *.service ; do
echo "Deploy ${service}"
rm -f /etc/systemd/system/${service}
cp ${service} /etc/systemd/system
systemctl enable ${service}
systemctl start ${service}
sleep 3
systemctl status ${service} --no-page -l
done
#systemctl status beehive-* --no-page -l