From 74013d82ab1e15f4e7e0f6c212a8047bc01eb3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20=C3=81lvaro?= Date: Wed, 6 May 2020 07:13:03 +0200 Subject: [PATCH] feat: Add healthcheck for gitlab service --- README.md | 47 ++++++++++++++++++++++- assets/build/install.sh | 10 +++++ assets/runtime/config/gitlabhq/gitlab.yml | 1 + docker-compose.yml | 8 +++- 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6c00aaa1..9698b3e9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/assets/build/install.sh b/assets/build/install.sh index 8b7fbe02..9127178b 100755 --- a/assets/build/install.sh +++ b/assets/build/install.sh @@ -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 <