docker: add housekeeping (#105)
Reviewed-on: #105 Co-authored-by: Michael Grote <michael.grote@posteo.de> Co-committed-by: Michael Grote <michael.grote@posteo.de>
This commit is contained in:
parent
f33ba3c932
commit
d1c18d270a
6 changed files with 75 additions and 0 deletions
|
@ -19,3 +19,6 @@
|
||||||
- role: mgrote_docker_compose_inline
|
- role: mgrote_docker_compose_inline
|
||||||
tags: "compose"
|
tags: "compose"
|
||||||
become: true
|
become: true
|
||||||
|
- role: mgrote_docker_housekeeping
|
||||||
|
tags: "housekeeping"
|
||||||
|
become: true
|
||||||
|
|
3
roles/mgrote_docker_housekeeping/defaults/main.yml
Normal file
3
roles/mgrote_docker_housekeeping/defaults/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
docker_housekeeping_schedule: "weekly"
|
||||||
|
...
|
14
roles/mgrote_docker_housekeeping/handlers/main.yml
Normal file
14
roles/mgrote_docker_housekeeping/handlers/main.yml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
- name: systemctl daemon-reload
|
||||||
|
become: true
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
daemon_reload: true
|
||||||
|
notify: Start timer
|
||||||
|
|
||||||
|
- name: Start timer
|
||||||
|
become: true
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: docker_housekeeping.timer
|
||||||
|
state: restarted
|
||||||
|
enabled: true
|
||||||
|
notify: systemctl daemon-reload
|
36
roles/mgrote_docker_housekeeping/tasks/main.yml
Normal file
36
roles/mgrote_docker_housekeeping/tasks/main.yml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
---
|
||||||
|
- name: Setup docker housekeeping tasks
|
||||||
|
become: true
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: docker_housekeeping.service.j2
|
||||||
|
dest: /etc/systemd/system/docker_housekeeping.service
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
notify:
|
||||||
|
- systemctl daemon-reload
|
||||||
|
|
||||||
|
- name: Setup timer
|
||||||
|
become: true
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: docker_housekeeping.timer.j2
|
||||||
|
dest: /etc/systemd/system/docker_housekeeping.timer
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
notify:
|
||||||
|
- systemctl daemon-reload
|
||||||
|
- Start timer
|
||||||
|
|
||||||
|
- name: Enable Units
|
||||||
|
become: true
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: "{{ item }}"
|
||||||
|
enabled: true
|
||||||
|
masked: false
|
||||||
|
with_items:
|
||||||
|
- docker_housekeeping.service
|
||||||
|
- docker_housekeeping.timer
|
||||||
|
notify:
|
||||||
|
- Start timer
|
||||||
|
...
|
|
@ -0,0 +1,8 @@
|
||||||
|
{{ file_header | default () }}
|
||||||
|
[Unit]
|
||||||
|
Description=Docker housekeeping tasks
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/docker system prune --force --filter "until=24h"
|
||||||
|
# https://docs.docker.com/config/pruning
|
|
@ -0,0 +1,11 @@
|
||||||
|
{{ file_header | default () }}
|
||||||
|
[Unit]
|
||||||
|
Description=Timer for docker_housekeeping backups.
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
# https://wiki.archlinux.org/title/systemd/Timers
|
||||||
|
OnCalendar={{ docker_housekeeping_schedule }}
|
||||||
|
RandomizedDelaySec=30 min
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target multi-user.target
|
Loading…
Reference in a new issue