mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
implemented check for anonymous volumes
This commit is contained in:
21
roles/health-docker-container/Readme.md
Normal file
21
roles/health-docker-container/Readme.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Health Check for Docker Containers
|
||||
|
||||
## Description
|
||||
|
||||
This Ansible role is designed to ensure the health of Docker containers running on a system. It includes a script that checks for unhealthy or exited Docker containers and sets up a systemd service and timer to regularly execute this check.
|
||||
|
||||
## Files
|
||||
|
||||
- `vars/main.yml`: Variable definitions for the script's directory.
|
||||
- `handlers/main.yml`: Handlers to reload and restart the systemd service and timer.
|
||||
- `files/health-docker-container.sh`: The script that checks the container health.
|
||||
- `tasks/main.yml`: Tasks to create necessary directories, copy scripts, and create systemd service and timer.
|
||||
- `templates/health-docker-container.service.j2`: Systemd service template.
|
||||
- `templates/health-docker-container.timer.j2`: Systemd timer template.
|
||||
- `meta/main.yml`: Meta information declaring dependencies for the role.
|
||||
|
||||
## Usage
|
||||
|
||||
To use this role, include it in your playbook and set the `path_administrator_scripts` variable to the desired path for the health check scripts.
|
||||
|
||||
Ensure that the `systemd_notifier` dependency is satisfied for error notifications.
|
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
docker_ps_grep_unhealthy="$(docker ps --filter health=unhealthy --format '{{.Names}}')"
|
||||
docker_ps_grep_exited="$(docker ps --filter status=exited --format '{{.Names}}')"
|
||||
exitcode=0
|
||||
if [ ! -z "$docker_ps_grep_unhealthy" ]
|
||||
then
|
||||
echo "Some docker containers are unhealthy: $docker_ps_grep_unhealthy"
|
||||
exitcode=1
|
||||
fi
|
||||
if [ ! -z "$docker_ps_grep_exited" ]
|
||||
then
|
||||
echo "Some docker containers exited: $docker_ps_grep_exited"
|
||||
exitcode=2
|
||||
fi
|
||||
if [ "$exitcode" -ne "0" ]
|
||||
then
|
||||
exit $exitcode
|
||||
fi
|
||||
echo "All docker containers are healthy."
|
||||
exit
|
11
roles/health-docker-container/handlers/main.yml
Normal file
11
roles/health-docker-container/handlers/main.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
- name: "reload health-docker-container.service"
|
||||
systemd:
|
||||
name: health-docker-container.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
- name: "restart health-docker-container.timer"
|
||||
systemd:
|
||||
name: health-docker-container.timer
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
2
roles/health-docker-container/meta/main.yml
Normal file
2
roles/health-docker-container/meta/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- systemd_notifier
|
22
roles/health-docker-container/tasks/main.yml
Normal file
22
roles/health-docker-container/tasks/main.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
- name: "create {{health_docker_container_folder}}"
|
||||
file:
|
||||
path: "{{health_docker_container_folder}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create health-docker-container.sh
|
||||
copy:
|
||||
src: health-docker-container.sh
|
||||
dest: "{{health_docker_container_folder}}health-docker-container.sh"
|
||||
|
||||
- name: create health-docker-container.service
|
||||
template: src=health-docker-container.service.j2 dest=/etc/systemd/system/health-docker-container.service
|
||||
notify: reload health-docker-container.service
|
||||
|
||||
- name: create health-docker-container.timer
|
||||
template:
|
||||
src: health-docker-container.timer.j2
|
||||
dest: "/etc/systemd/system/health-docker-container.timer"
|
||||
register: health_docker_container_timer
|
||||
changed_when: health_docker_container_timer.changed or activate_all_timers | default(false) | bool
|
||||
notify: restart health-docker-container.timer
|
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Checking docker health
|
||||
OnFailure=systemd-notifier@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash {{health_docker_container_folder}}health-docker-container.sh
|
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=starts health-docker-container.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{on_calendar_health_docker_container}}
|
||||
RandomizedDelaySec={{randomized_delay_sec}}
|
||||
Persistent=false
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
1
roles/health-docker-container/vars/main.yml
Normal file
1
roles/health-docker-container/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
||||
health_docker_container_folder: "{{path_administrator_scripts}}health-docker-container/"
|
Reference in New Issue
Block a user