Implemented docker health check

This commit is contained in:
Kevin Veen-Birkenbach 2022-12-25 13:40:38 +01:00
parent 5f26874fee
commit 442a85135e
7 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,7 @@
[Unit]
Description=Check docker status
OnFailure=systemd-email@%n.service
[Service]
Type=oneshot
ExecStart=/bin/bash /home/administrator/scripts/docker-health-check/docker-health-check.sh

View File

@ -0,0 +1,10 @@
#!/bin/sh
docker_ps_grep_unhealthy="$(docker ps | grep unhealthy)"
if [ -z "$docker_ps_grep_unhealthy" ]
then
echo "All docker containers are healthy."
exit
else
echo "Some docker containers are unhealthy: $docker_ps_grep_unhealthy"
exit 1
fi

View File

@ -0,0 +1,8 @@
[Unit]
Description=starts docker-health-check.service
[Timer]
OnCalendar=10:00
[Install]
WantedBy=timers.target

View File

@ -0,0 +1,12 @@
- name: "restart docker-health-check.service"
systemd:
name: docker-health-check.service
state: restarted
enabled: yes
daemon_reload: yes
- name: "restart docker-health-check.timer"
systemd:
name: docker-health-check.timer
state: restarted
enabled: yes
daemon_reload: yes

View File

@ -0,0 +1,2 @@
dependencies:
- native-systemd-email

View File

@ -0,0 +1,22 @@
- name: "create /home/administrator/scripts/docker-health-check/"
file:
path: "/home/administrator/scripts/docker-health-check"
state: directory
mode: 0755
- name: create docker-health-check.sh
copy:
src: docker-health-check.sh
dest: "/home/administrator/scripts/docker-health-check/docker-health-check.sh"
- name: create docker-health-check.service
copy:
src: docker-health-check.service
dest: "/etc/systemd/system/docker-health-check.service"
notify: restart docker-health-check.service
- name: create docker-health-check.timer
copy:
src: docker-health-check.timer
dest: "/etc/systemd/system/docker-health-check.timer"
notify: restart docker-health-check.timer

View File

@ -1,3 +1,4 @@
dependencies: dependencies:
- native-docker-volume-backup - native-docker-volume-backup
- native-user-administrator - native-user-administrator
- native-docker-health-check