feat: Add healthcheck for gitlab service

This commit is contained in:
Carlos Álvaro 2020-05-06 07:13:03 +02:00 committed by Niclas Mietz
parent ae6fad48c4
commit 74013d82ab
4 changed files with 63 additions and 3 deletions

View File

@ -61,8 +61,9 @@
- [Import Repositories](#import-repositories)
- [Upgrading](#upgrading)
- [Shell Access](#shell-access)
- [Features](#features)
- [Container Registry](docs/container_registry.md)
- [Monitoring](#monitoring)
- [Health Check](#health-check)
- [Container Registry](docs/container_registry.md)
- [References](#references)
# Introduction
@ -1333,6 +1334,48 @@ For debugging and maintenance purposes you may want access the containers shell.
docker exec -it gitlab bash
```
# Monitoring
You can monitor your GitLab instance status as described in the [official documentation](https://docs.gitlab.com/ee/user/admin_area/monitoring/health_check.html), for example:
```bash
curl 'https://gitlab.example.com/-/liveness'
```
On success, the endpoint will return a `200` HTTP status code, and a response like below.
```bash
{
"status": "ok"
}
```
To do that you will need to set the environment variable `GITLAB_MONITORING_IP_WHITELIST` to allow your IP or subnet to make requests to your GitLab instance.
## Health Check
You can also set your `docker-compose.yml` [healthcheck](https://docs.docker.com/compose/compose-file/compose-file-v2/#healthcheck) configuration to make periodic checks:
```yml
version: '2.3'
services:
gitlab:
image: sameersbn/gitlab:12.7.7
healthcheck:
test: ["CMD", "/usr/local/sbin/healthcheck"]
interval: 1m
timeout: 5s
retries: 5
start_period: 2m
```
Then you will be able to consult the healthcheck log by executing:
```bash
docker inspect --format "{{json .State.Health }}" $(docker-compose ps -q gitlab) | jq
```
# References
* https://github.com/gitlabhq/gitlabhq

View File

@ -426,6 +426,16 @@ programs=sshd,nginx,mail_room,cron
priority=20
EOF
# configure healthcheck script
## https://docs.gitlab.com/ee/user/admin_area/monitoring/health_check.html
cat > /usr/local/sbin/healthcheck <<EOF
#!/bin/bash
url=http://localhost/-/liveness
curl -s \$url
[[ "\$(curl -s -o /dev/null -I -w '%{http_code}' \$url)" == "200" ]]
EOF
chmod +x /usr/local/sbin/healthcheck
# purge build dependencies and cleanup apt
DEBIAN_FRONTEND=noninteractive apt-get purge -y --auto-remove ${BUILD_DEPENDENCIES}
rm -rf /var/lib/apt/lists/*

View File

@ -1149,6 +1149,7 @@ production: &base
# puma_sampler_interval: 5
# IP whitelist to access monitoring endpoints
ip_whitelist:
- 127.0.0.0/8
- {{GITLAB_MONITORING_IP_WHITELIST}}
# Sidekiq exporter is webserver built in to Sidekiq to expose Prometheus metrics

View File

@ -1,4 +1,4 @@
version: '2'
version: '2.3'
services:
redis:
@ -31,6 +31,12 @@ services:
- "10022:22"
volumes:
- gitlab-data:/home/git/data:Z
healthcheck:
test: ["CMD", "/usr/local/sbin/healthcheck"]
interval: 5m
timeout: 10s
retries: 3
start_period: 5m
environment:
- DEBUG=false