Skip to content
This repository was archived by the owner on Mar 15, 2019. It is now read-only.

Commit e3a74a5

Browse files
author
Julien Neuhart
authored
Adding health check for others modules than Graylog (#44)
* adding health check for others modules than Graylog * updating README.md
1 parent 141aa38 commit e3a74a5

File tree

10 files changed

+107
-34
lines changed

10 files changed

+107
-34
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ The Toolbox is a simple container which is used to:
184184
* Generates the `.htdigest` file for authentication to the Traefik dashboard on environments <> `local`
185185
* Generates the SHA2 password and secret pepper for Graylog authentication
186186
* Checks if Graylog is ready to receive logs from others containers
187+
* Checks if others containers have been successfully started
187188

188189
### Traefik
189190

config/orbit/orbit-scripts.yml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,7 @@ commands:
6666

6767
- use: "script-traefik-self-signed-certificate"
6868
run:
69-
{{ if eq "local" .EnvFiles.Config.ENV }}
7069
- docker-compose -p {{ .EnvFiles.Config.ENV }}{{ .Values.Project.name }} -f modules/toolbox/docker-compose.yml run toolbox /bin/sh -c /scripts/traefik-self-signed-certificate.sh
71-
{{ else if eq "windows" .Os }}
72-
- cmd.exe /c echo Skipping self-signed certificate generation ...
73-
{{ else }}
74-
- echo Skipping self-signed certificate generation ...
75-
{{ end }}
7670

7771
# |--------------------------------------------------------------------------
7872
# | orbit run script-traefik-htdigest
@@ -86,13 +80,7 @@ commands:
8680

8781
- use: "script-traefik-htdigest"
8882
run:
89-
{{ if ne "local" .EnvFiles.Config.ENV }}
9083
- docker-compose -p {{ .EnvFiles.Config.ENV }}{{ .Values.Project.name }} -f modules/toolbox/docker-compose.yml run toolbox /bin/sh -c /scripts/traefik-htdigest.sh
91-
{{ else if eq "windows" .Os }}
92-
- cmd.exe /c echo Skipping .htdigest file generation ...
93-
{{ else }}
94-
- echo Skipping .htdigest file generation ...
95-
{{ end }}
9684

9785
# |--------------------------------------------------------------------------
9886
# | orbit run script-graylog-secrets
@@ -109,15 +97,20 @@ commands:
10997
# | orbit run script-graylog-health-check
11098
# |--------------------------------------------------------------------------
11199
# |
112-
# | Generates Graylog secrets.
100+
# | Checks if Graylog is correctly running.
113101
# |
114102

115103
- use: "script-graylog-health-check"
116104
run:
117-
{{ if eq true .Values.Modules.graylog.enable }}
118105
- docker-compose -p {{ .EnvFiles.Config.ENV }}{{ .Values.Project.name }} -f modules/toolbox/docker-compose.yml run toolbox /bin/sh -c /scripts/graylog-health-check.sh
119-
{{ else if eq "windows" .Os }}
120-
- cmd.exe /c echo Skipping Graylog healtch check ...
121-
{{ else }}
122-
- echo Skipping Skipping Graylog healtch check ...
123-
{{ end }}
106+
107+
# |--------------------------------------------------------------------------
108+
# | orbit run script-others-modules-health-check
109+
# |--------------------------------------------------------------------------
110+
# |
111+
# | Checks if others modules are correctly running.
112+
# |
113+
114+
- use: "script-others-modules-health-check"
115+
run:
116+
- docker-compose -p {{ .EnvFiles.Config.ENV }}{{ .Values.Project.name }} -f modules/toolbox/docker-compose.yml run toolbox /bin/sh -c /scripts/others-modules-health-check.sh

modules/toolbox/docker-compose.blueprint.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ services:
1515
- VIRTUAL_HOST={{ $virtualhost }}
1616
{{- end }}
1717
{{- end }}
18-
{{- if ne "local" .EnvFiles.Config.ENV }}
18+
- ENV={{ .EnvFiles.Config.ENV }}
1919
- TRAEFIK_USER={{ .Values.Modules.traefik.user }}
2020
- TRAEFIK_PASSWORD={{ .EnvFiles.Config.TRAEFIK_PASSWORD }}
21-
{{- end }}
2221
- GRAYLOG_ROOT_PASSWORD_SHA2={{ .EnvFiles.Config.GRAYLOG_PASSWORD }}
22+
- GRAYLOG_ENABLED={{ .Values.Modules.graylog.enable }}
23+
- MYSQL_ENABLED={{ .Values.Modules.mysql.enable }}
24+
- REDIS_ENABLED={{ .Values.Modules.redis.enable }}
25+
- RABBITMQ_ENABLED={{ .Values.Modules.rabbitmq.enable }}
2326
labels:
2427
- traefik.enable=false
2528
volumes:
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#!/bin/sh
22

3-
echo Waiting Graylog ...;
3+
if [ "$GRAYLOG_ENABLED" == "false" ]; then
4+
echo Skipping Graylog health check ...;
5+
exit 0;
6+
fi;
47

5-
attempts=30;
6-
while [[ $attempts -ne 0 ]]; do
7-
nc -z graylog-server 9000 > /dev/null 2>&1;
8-
if [[ $? -eq 0 ]]; then
9-
exit 0;
10-
fi;
11-
sleep 5s;
12-
attempts=`expr $attempts - 1`;
13-
echo .;
14-
done;
8+
if ! /bin/sh -c "/scripts/health-check.sh Graylog graylog-server 9000"; then
9+
exit 1;
10+
fi;
1511

16-
echo Graylog has not started, aborting other containers startup ...;
17-
exit 1;
12+
exit 0;

modules/toolbox/scripts/graylog-secrets.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/sh
22

3+
if [ "$GRAYLOG_ENABLED" == "false" ]; then
4+
echo Skipping Graylog secrets generation ...;
5+
exit 0;
6+
fi;
7+
38
sedi()
49
{
510
sed --version >/dev/null 2>&1 && sed -i -- "$@" || sed -i "" "$@";
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
SERVICE=$1;
4+
HOST=$2;
5+
PORT=$3;
6+
7+
spin='-\|/';
8+
i=0;
9+
10+
attempts=600;
11+
while [ $attempts -ne 0 ]; do
12+
13+
nc -z $HOST $PORT > /dev/null 2>&1;
14+
15+
if [ $? -eq 0 ]; then
16+
printf "\r[success] $SERVICE is ready!\n";
17+
exit 0;
18+
fi;
19+
20+
i=$(( (i+1) %4 ));
21+
printf "\r${spin:$i:1} Waiting $SERVICE ...";
22+
sleep .1
23+
24+
attempts=`expr $attempts - 1`;
25+
done;
26+
27+
printf "\r[error] $SERVICE failed to launch!\n";
28+
exit 1;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
3+
if ! /bin/sh -c "/scripts/health-check.sh PHP-FPM php-fpm 9000"; then
4+
exit 1;
5+
fi;
6+
7+
if ! /bin/sh -c "/scripts/health-check.sh NGINX nginx 80"; then
8+
exit 1;
9+
fi;
10+
11+
if [ "$MYSQL_ENABLED" == "false" ]; then
12+
echo Skipping MySQL and phpMyAdmin health check ...;
13+
else
14+
if ! /bin/sh -c "/scripts/health-check.sh MySQL mysql 3306"; then
15+
exit 1;
16+
fi;
17+
18+
if [ "$ENV" != "local" ]; then
19+
echo Skipping phpMyAdmin health check ...;
20+
elif ! /bin/sh -c "/scripts/health-check.sh phpMyAdmin phpmyadmin 80"; then
21+
exit 1;
22+
fi;
23+
fi;
24+
25+
if [ "$REDIS_ENABLED" == "false" ]; then
26+
echo Skipping Redis health check ...;
27+
elif ! /bin/sh -c "/scripts/health-check.sh Redis redis 6379"; then
28+
exit 1;
29+
fi;
30+
31+
if [ "$RABBITMQ_ENABLED" == "false" ]; then
32+
echo Skipping RabbitMQ health check ...;
33+
elif ! /bin/sh -c "/scripts/health-check.sh RabbitMQ rabbitmq 15672"; then
34+
exit 1;
35+
fi;
36+
37+
exit 0;

modules/toolbox/scripts/traefik-htdigest.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/sh
22

3+
if [ "$ENV" == "local" ]; then
4+
echo Skipping .htdigest file generation ...;
5+
exit 0;
6+
fi;
7+
38
echo Generating .htdigest file ...;
49

510
rm -f /generated/traefik/auth/.htdigest;

modules/toolbox/scripts/traefik-self-signed-certificate.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/sh
22

3+
if [ "$ENV" != "local" ]; then
4+
echo Skipping self-signed certificate generation ...;
5+
exit 0;
6+
fi;
7+
38
if [ ! -f "/generated/traefik/certs/$VIRTUAL_HOST.key" ]; then
49
echo Generating the self-signed certificate ...
510

orbit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ commands:
8989
- orbit run mysql-up -c config/orbit/orbit-up.yml -v Project,config/project.yml;Modules,config/modules.yml -e Config,config/.env
9090
- orbit run redis-up -c config/orbit/orbit-up.yml -v Project,config/project.yml;Modules,config/modules.yml -e Config,config/.env
9191
- orbit run rabbitmq-up -c config/orbit/orbit-up.yml -v Project,config/project.yml;Modules,config/modules.yml -e Config,config/.env
92+
- orbit run script-others-modules-health-check -c config/orbit/orbit-scripts.yml -v Project,config/project.yml;Modules,config/modules.yml -e Config,config/.env
9293
- orbit run notify -c config/orbit/orbit-notify.yml -r message_id=up_success
9394
- docker ps
9495

0 commit comments

Comments
 (0)