forked from combro2k/docker-icinga2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
339 lines (278 loc) · 9.78 KB
/
Makefile
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
.PHONY: all help build run builddocker rundocker kill rm-image rm clean enter logs
all: help
help:
@echo ""
@echo "-- Help Menu"
@echo "" This is merely a base image for usage read the README file
@echo "" 1. make run - build and run docker container
@echo "" 2. make build - build docker container
@echo "" 3. make clean - kill and remove docker container
@echo "" 4. make enter - execute an interactive bash in docker container
@echo "" 3. make logs - follow the logs of docker container
auto: temp waitforport4080 wait next waitforport4080
build: NAME TAG builddocker
# run a plain container
run: rm build waitformysql rundocker
# run a container that requires mysql temporarily
temp: HOSTNAME DOMAIN MYSQL_PASS rm build mysqltemp waitformysqltemp runtemp
next: grab rmtemp rmmysqltemp wait mover wait prod
# run a container that requires mysql in production with persistent data
# HINT: use the grabmysqldatadir recipe to grab the data directory automatically from the above runmysql
prod: HOSTNAME DOMAIN DATADIR MYSQL_PASS mysqlCID waitformysql runprod
mailvars: SMTP_ENABLED SMTP_USER SMTP_PASS SMTP_DOMAIN SMTP_PORT DOMAIN HOSTNAME
offtemp:
$(eval TMP := $(shell mktemp -d --suffix=DOCKERTMP))
chmod 777 $(TMP)
echo $TMP
rundocker:
$(eval NAME := $(shell cat NAME))
$(eval TAG := $(shell cat TAG))
@docker run --name=$(NAME) \
--cidfile="cid" \
-d \
-P \
-v /var/run/docker.sock:/run/docker.sock \
-v $(shell which docker):/bin/docker \
-t $(TAG)
runtemp:
$(eval NAME := $(shell cat NAME))
$(eval TAG := $(shell cat TAG))
$(eval DOMAIN := $(shell cat DOMAIN))
$(eval HOSTNAME := $(shell cat HOSTNAME))
@docker run --name=$(NAME) \
--cidfile="tempCID" \
-d \
-p 4080:80 \
-p 4443:443 \
-p 5665:5665 \
--link `cat NAME`-mysqltemp:mysql \
-t $(TAG)
runprod:
$(eval DATADIR := $(shell cat DATADIR))
$(eval NAME := $(shell cat NAME))
$(eval TAG := $(shell cat TAG))
$(eval SMTP_ENABLED := $(shell cat SMTP_ENABLED))
$(eval SMTP_USER := $(shell cat SMTP_USER))
$(eval SMTP_PASS := $(shell cat SMTP_PASS))
$(eval SMTP_DOMAIN := $(shell cat SMTP_DOMAIN))
$(eval SMTP_PORT := $(shell cat SMTP_PORT))
$(eval DOMAIN := $(shell cat DOMAIN))
$(eval HOSTNAME := $(shell cat HOSTNAME))
@docker run --name=$(NAME) \
--cidfile="icinga2CID" \
-d \
-p 4080:80 \
-p 4443:443 \
-p 5665:5665 \
--env="SMTP_ENABLED=$(SMTP_ENABLED)" \
--env="SMTP_USER=$(SMTP_USER)" \
--env="SMTP_PASS=$(SMTP_PASS)" \
--env="SMTP_DOMAIN=$(SMTP_DOMAIN)" \
--env="SMTP_PORT=$(SMTP_PORT)" \
--env="DOMAIN=$(DOMAIN)" \
--env="HOSTNAME=$(HOSTNAME)" \
--link `cat NAME`-mysql:mysql \
-v $(DATADIR)/lib/icinga2:/var/lib/icinga2 \
-v $(DATADIR)/etc/icinga:/etc/icinga \
-v $(DATADIR)/etc/icinga2:/etc/icinga2 \
-v $(DATADIR)/etc/icinga2-classicui:/etc/icinga2-classicui \
-v $(DATADIR)/etc/icingaweb2:/etc/icingaweb2 \
-h $(HOSTNAME).$(DOMAIN) \
-t $(TAG)
debug:
@echo 'pausing for mysql to settle'
-@bash wait.sh
@echo -n ' use "make logs" at this point to see if it fails on mysql, if so wait for a bit and and then try "make temp" again'
$(eval DATADIR := $(shell cat DATADIR))
$(eval TMP := $(shell mktemp -d --suffix=DOCKERTMP))
-@chmod 777 $(TMP)
$(eval NAME := $(shell cat NAME))
$(eval TAG := $(shell cat TAG))
@docker run --name=$(NAME) \
--cidfile="debugCID" \
-d \
-p 4080:80 \
-p 4443:443 \
-p 5665:5665 \
--link `cat NAME`-mysql:mysql \
-v /var/run/docker.sock:/run/docker.sock \
-v $(DATADIR)/lib/icinga2:/var/lib/icinga2 \
-v $(DATADIR)/etc/icinga:/etc/icinga \
-v $(DATADIR)/etc/icinga2:/etc/icinga2 \
-v $(DATADIR)/etc/icinga2-classicui:/etc/icinga2-classicui \
-v $(DATADIR)/etc/icingaweb2:/etc/icingaweb2 \
-v $(TMP):/tmp \
-v $(shell which docker):/bin/docker \
-t $(TAG) /bin/bash
builddocker:
@docker build -t `cat TAG` .
kill: SHELL:=/bin/bash
kill:
-@ echo "killing Icinga2 container"
-@docker kill `cat icinga2CID`
rm-image: SHELL:=/bin/bash
rm-image:
-@ echo "removing Icinga2 container"
-@docker rm `cat icinga2CID`
-@rm -f icinga2CID
rm: kill rm-image
rmtemp: killtemp rmtemp-image
killtemp: SHELL:=/bin/bash
killtemp:
-@ echo "killing Icinga2 container"
-@docker kill `cat tempCID`
rmtemp-image: SHELL:=/bin/bash
rmtemp-image:
-@ echo "removing Icinga2 container"
-@docker rm `cat tempCID`
-@rm -f tempCID
clean: rmall rmtemp
enter:
docker exec -i -t `cat icinga2CID` /bin/bash
templogs:
docker logs -f `cat tempCID`
logs:
docker logs -f `cat icinga2CID`
NAME:
@while [ -z "$$NAME" ]; do \
read -r -p "Enter the name you wish to associate with this container [NAME]: " NAME; echo "$$NAME">NAME; cat NAME; \
done ;
TAG:
@while [ -z "$$TAG" ]; do \
read -r -p "Enter the tag you wish to associate with this container [TAG]: " TAG; echo "$$TAG">TAG; cat TAG; \
done ;
DOMAIN:
@while [ -z "$$DOMAIN" ]; do \
read -r -p "Enter the DOMAIN you wish to associate with this container [DOMAIN]: " DOMAIN; echo "$$DOMAIN">DOMAIN; cat DOMAIN; \
done ;
HOSTNAME:
@while [ -z "$$THIS_HOSTNAME" ]; do \
read -r -p "Enter the HOSTNAME you wish to associate with this container [HOSTNAME]: " THIS_HOSTNAME; echo "$$THIS_HOSTNAME">HOSTNAME; cat HOSTNAME; \
done ;
SMTP_USER:
@while [ -z "$$SMTP_USER" ]; do \
read -r -p "Enter the smtp_user you wish to associate with this container [SMTP_USER]: " SMTP_USER; echo "$$SMTP_USER">SMTP_USER; cat SMTP_USER; \
done ;
SMTP_PASS:
@while [ -z "$$SMTP_PASS" ]; do \
read -r -p "Enter the smtp_pass you wish to associate with this container [SMTP_PASS]: " SMTP_PASS; echo "$$SMTP_PASS">SMTP_PASS; cat SMTP_PASS; \
done ;
SMTP_PORT:
@while [ -z "$$SMTP_PORT" ]; do \
read -r -p "Enter the port you wish to associate with this container [SMTP_PORT]: " SMTP_PORT; echo "$$SMTP_PORT">SMTP_PORT; cat SMTP_PORT; \
done ;
SMTP_ENABLED:
@while [ -z "$$SMTP_ENABLED" ]; do \
read -r -p "If you wish to enable smtp for this container type anything here [SMTP_ENABLED]: " SMTP_ENABLED; echo "$$SMTP_ENABLED">SMTP_ENABLED; cat SMTP_ENABLED; \
done ;
SMTP_DOMAIN:
@while [ -z "$$SMTP_DOMAIN" ]; do \
read -r -p "Enter the SMTP_DOMAIN you wish to associate with this container [SMTP_DOMAIN]: " SMTP_DOMAIN; echo "$$SMTP_DOMAIN">SMTP_DOMAIN; cat SMTP_DOMAIN; \
done ;
# MYSQL additions
# use these to generate a mysql container that may or may not be persistent
mysqlCID:
$(eval DATADIR := $(shell cat DATADIR))
docker run \
--cidfile="mysqlCID" \
--name `cat NAME`-mysql \
-d \
-v $(DATADIR)/mysql:/var/lib/mysql \
mysql:5.7
rmmysql: mysqlCID-rmkill
mysqlCID-rmkill:
-@echo "killing mysql container"
-@docker kill `cat mysqlCID`
-@echo "removing mysql container"
-@docker rm `cat mysqlCID`
-@echo "removing mysqlCID"
-@rm -f mysqlCID
rmmysqltemp: mysqltempCID-rmkill
mysqltempCID-rmkill:
-@echo "killing mysql temp container"
-@docker kill `cat mysqltempCID`
-@echo "removing mysql temp container"
-@docker rm `cat mysqltempCID`
-@echo "removing mysqltempCID"
-@rm -f mysqltempCID
# This one is ephemeral and will not persist data
mysqltemp: mysqltempCID
mysqltempCID:
docker run \
--cidfile="mysqltempCID" \
--name `cat NAME`-mysqltemp \
-e MYSQL_ROOT_PASSWORD=`cat MYSQL_PASS` \
-d \
mysql:5.7
rmall: rm rmtemp rmmysql rmmysqltemp
grab: grabicingadir grabmysqldatadir mvdatadir
grabmysqldatadir:
-mkdir -p datadir
docker cp `cat mysqltempCID`:/var/lib/mysql - |sudo tar -C datadir/ -pxvf -
grabicingadir:
-mkdir -p datadir/lib
-mkdir -p datadir/etc
docker cp `cat tempCID`:/var/lib/icinga2 - |sudo tar -C datadir/lib/ -pxvf -
docker cp `cat tempCID`:/etc/icinga - |sudo tar -C datadir/etc/ -pxvf -
docker cp `cat tempCID`:/etc/icinga2 - |sudo tar -C datadir/etc/ -pxvf -
docker cp `cat tempCID`:/etc/icinga2-classicui - |sudo tar -C datadir/etc/ -pxvf -
docker cp `cat tempCID`:/etc/icingaweb2 - |sudo tar -C datadir/etc/ -pxvf -
mvdatadir:
sudo mv datadir /tmp
echo /tmp/datadir > DATADIR
echo "Move datadir out of tmp and update DATADIR here accordingly for persistence"
DATADIR:
@while [ -z "$$DATADIR" ]; do \
read -r -p "Enter the destination of the data directory you wish to associate with this container [DATADIR]: " DATADIR; echo "$$DATADIR">DATADIR; cat DATADIR; \
done ;
MYSQL_PASS:
@tr -cd '[:alnum:]' < /dev/urandom | fold -w20 | head -n1 > MYSQL_PASS
askMYSQL_PASS:
@while [ -z "$$MYSQL_PASS" ]; do \
read -r -p "Enter the MySQL password you wish to associate with this container [MYSQL_PASS]: " MYSQL_PASS; echo "$$MYSQL_PASS">MYSQL_PASS; cat MYSQL_PASS; \
done ;
update: update-config rm prod
update-config:
docker exec -i -t `cat icinga2CID` sh -c '/usr/sbin/icinga2 node update-config'
pki:
-@rm -f NEW_PKI_CN
@while [ -z "$$NEW_PKI_CN" ]; do \
read -r -p "Enter the common name (CN) you wish to this icinga2 instance [NEW_PKI_CN]: " NEW_PKI_CN; echo "'$$NEW_PKI_CN'">NEW_PKI_CN; cat NEW_PKI_CN; \
done ;
docker exec -i -t `cat icinga2CID` sh -c "/usr/sbin/icinga2 pki ticket --cn `cat NEW_PKI_CN`"
-@rm -f NEW_PKI_CN
nodelist:
docker exec -i -t `cat icinga2CID` sh -c '/usr/sbin/icinga2 node list'
mover:
-@mkdir -p /exports/icinga2
-@cd /exports; tar zcf /exports/icinga2-`date -I`.tar.gz icinga2
-@rm -Rf /exports/icinga2/datadir
-@mv /tmp/datadir /exports/icinga2/
-@echo /exports/icinga2/datadir > DATADIR
hardclean: hardcleanMEAT rmall
hardcleanMEAT:
-@rm -Rf /exports/icinga2 &>/dev/null
-@rm -f DATADIR &>/dev/null
wait:
-@sleep 5
waitformysql:
-@sleep 3
-@bash wait.sh `cat mysqlCID`
-@sleep 3
waitformysqltemp:
-@sleep 3
-@bash wait.sh `cat mysqltempCID`
-@sleep 3
-@echo 'discombobulating combubulator'
-@sleep 3
-@echo 'combobulating discombubulator'
-@sleep 3
-@echo 'seek quell state'
-@sleep 3
waitforport4080:
-@sleep 3
@echo -n "Waiting for port 4080 to become available"
@while ! curl --output /dev/null --silent --head --fail http://localhost:4080; do sleep 2 && echo -n .; done;
@echo " check port 4080, it appears that now it is up!"
-@sleep 3
restart: rm runprod