mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-25 22:21:04 +01:00
Compare commits
No commits in common. "29f134005fa02b57067fba01bf148d276c954c30" and "dfc0dbbffa13430f4bb938be52c9d49f85af22af" have entirely different histories.
29f134005f
...
dfc0dbbffa
10
README.md
10
README.md
@ -30,12 +30,12 @@ This software allows to setup the docker following applications:
|
||||
#### Native Applications
|
||||
|
||||
This software shipts the following tools which are natively setup on the server:
|
||||
- [Backups Cleanup](./roles/cleanup-backups-timer/README.md) - Cleans up old backups
|
||||
- [Btrfs Health Check](./roles/health-btrfs/README.md) - Checks the health of Btrfs file systems
|
||||
- [Docker Health Check](./roles/health-docker/) - Checks the health of docker containers
|
||||
- [Backups Cleanup](./roles/backups-cleanup-timer/README.md) - Cleans up old backups
|
||||
- [Btrfs Health Check](./roles/btrfs-health-check/README.md) - Checks the health of Btrfs file systems
|
||||
- [Docker Health Check](./roles/docker-health-check/) - Checks the health of docker containers
|
||||
- [Docker Reverse Proxy](./roles/docker-reverse-proxy/README.md) - Docker Reverse Proxy Solution
|
||||
- [Docker Volume Backup](./roles/backup-docker-to-local/) - Backup Solution for Docker Volumes
|
||||
- [Pull Primary Backups](./roles/backup-remote-to-local/README.md) - Pulls the backups from another server and stores them
|
||||
- [Docker Volume Backup](./roles/docker-volume-backup/) - Backup Solution for Docker Volumes
|
||||
- [Pull Primary Backups](./roles/backups-consumer/README.md) - Pulls the backups from another server and stores them
|
||||
- [Wireguard](./roles/wireguard/README.md) - Integrates the server in an wireguard vpn
|
||||
|
||||
### Server Administration
|
||||
|
12
playbook.yml
12
playbook.yml
@ -3,7 +3,7 @@
|
||||
hosts: all
|
||||
become: true
|
||||
roles:
|
||||
- update
|
||||
- system-update
|
||||
|
||||
- name: servers host setup
|
||||
hosts: servers
|
||||
@ -11,9 +11,9 @@
|
||||
roles:
|
||||
- system-security
|
||||
- journalctl
|
||||
- health-disc-space
|
||||
- cleanup-disc-space
|
||||
- health-btrfs
|
||||
- disc-space-check
|
||||
- free-disc-space
|
||||
- btrfs-health-check
|
||||
|
||||
# Wireguard Rollen
|
||||
- name: setup standard wireguard
|
||||
@ -204,7 +204,7 @@
|
||||
hosts: replica_backup
|
||||
become: true
|
||||
roles:
|
||||
- role: backup-remote-to-local
|
||||
- role: backups-consumer
|
||||
|
||||
## PC services
|
||||
- name: general host setup
|
||||
@ -321,4 +321,4 @@
|
||||
hosts: backup_to_usb
|
||||
become: true
|
||||
roles:
|
||||
- backup-data-to-usb
|
||||
- backup-to-usb
|
@ -1,6 +0,0 @@
|
||||
- name: "reload backup-data-to-usb.service"
|
||||
systemd:
|
||||
name: backup-data-to-usb.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
dependencies:
|
||||
- role: cleanup-backups-service
|
@ -1,12 +0,0 @@
|
||||
- name: "reload backup-docker-to-local.service"
|
||||
systemd:
|
||||
name: backup-docker-to-local.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
|
||||
- name: "restart backup-docker-to-local.timer"
|
||||
systemd:
|
||||
name: backup-docker-to-local.timer
|
||||
state: started
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -1,38 +0,0 @@
|
||||
- name: install pandas system wide
|
||||
community.general.pacman:
|
||||
name:
|
||||
- lsof
|
||||
- python-pandas
|
||||
state: present
|
||||
|
||||
- name: pull backup-docker-to-local.git
|
||||
git:
|
||||
repo: "https://github.com/kevinveenbirkenbach/backup-docker-to-local.git"
|
||||
dest: "{{docker_volume_backup_folder}}"
|
||||
update: yes
|
||||
register: git_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: Warn if repo is not reachable
|
||||
debug:
|
||||
msg: "Warning: Repository is not reachable."
|
||||
when: git_result.failed
|
||||
|
||||
- name: configure backup-docker-to-local.service
|
||||
template:
|
||||
src: backup-docker-to-local.service.j2
|
||||
dest: /etc/systemd/system/backup-docker-to-local.service
|
||||
notify: reload backup-docker-to-local.service
|
||||
|
||||
- name: configure backup-docker-to-local.timer.tpl
|
||||
template: src=backup-docker-to-local.timer.j2 dest=/etc/systemd/system/backup-docker-to-local.timer
|
||||
register: backup_docker_to_local_timer
|
||||
changed_when: backup_docker_to_local_timer.changed or activate_all_timers | default(false) | bool
|
||||
notify: restart backup-docker-to-local.timer
|
||||
|
||||
- name: create {{docker_volume_backup_folder}}databases.csv
|
||||
copy:
|
||||
src: "{{ inventory_dir }}/files/{{ inventory_hostname }}{{docker_volume_backup_folder}}databases.csv"
|
||||
dest: "{{docker_volume_backup_folder}}databases.csv"
|
||||
owner: root
|
||||
group: root
|
@ -1,7 +0,0 @@
|
||||
[Unit]
|
||||
Description=docker volume backup
|
||||
OnFailure=systemd-notifier@%n.service cleanup-failed-docker-backups.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/python {{docker_volume_backup_folder}}backup-docker-to-local.py
|
@ -1 +0,0 @@
|
||||
docker_volume_backup_folder: "{{path_administrator_scripts}}backup-docker-to-local/"
|
@ -1,11 +0,0 @@
|
||||
- name: "reload backup-remote-to-local service"
|
||||
systemd:
|
||||
name: backup-remote-to-local.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
- name: "restart backup-remote-to-local timer"
|
||||
systemd:
|
||||
name: backup-remote-to-local.timer
|
||||
state: started
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -1,5 +0,0 @@
|
||||
dependencies:
|
||||
- git
|
||||
- systemd_notifier
|
||||
- cleanup-backups-timer
|
||||
- cleanup-failed-docker-backups
|
@ -1,28 +0,0 @@
|
||||
- name: "create {{docker_pull_primary_backups_folder}}"
|
||||
file:
|
||||
path: "{{docker_pull_primary_backups_folder}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create backup-remote-to-local.sh
|
||||
copy:
|
||||
src: backup-remote-to-local.sh
|
||||
dest: "{{docker_pull_primary_backups_folder}}backup-remote-to-local.sh"
|
||||
mode: 0755
|
||||
|
||||
- name: create backup-remote-to-local.service
|
||||
template: src=backup-remote-to-local.service.j2 dest=/etc/systemd/system/backup-remote-to-local.service
|
||||
notify: reload backup-remote-to-local service
|
||||
|
||||
- name: create backup-remote-to-local.timer
|
||||
template: src=backup-remote-to-local.timer.j2 dest=/etc/systemd/system/backup-remote-to-local.timer
|
||||
register: backup_remote_to_local_timer
|
||||
changed_when: backup_remote_to_local_timer.changed or activate_all_timers | default(false) | bool
|
||||
notify: restart backup-remote-to-local timer
|
||||
|
||||
- name: create backup-remote-to-local.sh
|
||||
template:
|
||||
src: backup-remote-to-local.sh.j2
|
||||
dest: "{{docker_pull_primary_backups_folder}}backup-remote-to-local.sh"
|
||||
mode: 0755
|
||||
|
@ -1,7 +0,0 @@
|
||||
[Unit]
|
||||
Description=pull remote backups
|
||||
OnFailure=systemd-notifier@%n.service cleanup-failed-docker-backups.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/bash {{docker_pull_primary_backups_folder}}backup-remote-to-local.sh
|
@ -1,4 +1,4 @@
|
||||
# backup-data-to-usb
|
||||
# backup-to-usb
|
||||
|
||||
This Ansible role automates the process of performing backups to a swappable USB device.
|
||||
|
@ -21,7 +21,7 @@ def main():
|
||||
machine_id = subprocess.run(["sha256sum", "/etc/machine-id"], capture_output=True, text=True).stdout.strip()[:64]
|
||||
print(f"machine id: {machine_id}")
|
||||
|
||||
versions_path = os.path.join(backup_to_usb_destination_path, f"{machine_id}/backup-data-to-usb/")
|
||||
versions_path = os.path.join(backup_to_usb_destination_path, f"{machine_id}/backup-to-usb/")
|
||||
print(f"versions path: {versions_path}")
|
||||
|
||||
if not os.path.isdir(versions_path):
|
6
roles/backup-to-usb/handlers/main.yml
Normal file
6
roles/backup-to-usb/handlers/main.yml
Normal file
@ -0,0 +1,6 @@
|
||||
- name: "reload backup-to-usb.service"
|
||||
systemd:
|
||||
name: backup-to-usb.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
3
roles/backup-to-usb/meta/main.yml
Normal file
3
roles/backup-to-usb/meta/main.yml
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
dependencies:
|
||||
- role: backups-cleanup-service
|
@ -1,6 +1,6 @@
|
||||
- name: Copy backup script to the scripts directory
|
||||
copy:
|
||||
src: backup-data-to-usb.python
|
||||
src: backup-to-usb.python
|
||||
dest: "{{ backup_to_usb_script_path }}"
|
||||
owner: root
|
||||
group: root
|
||||
@ -8,9 +8,9 @@
|
||||
|
||||
- name: Copy systemd service to systemd directory
|
||||
template:
|
||||
src: backup-data-to-usb.service.j2
|
||||
dest: /etc/systemd/system/backup-data-to-usb.service
|
||||
src: backup-to-usb.service.j2
|
||||
dest: /etc/systemd/system/backup-to-usb.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
notify: reload backup-data-to-usb.service
|
||||
notify: reload backup-to-usb.service
|
@ -5,7 +5,7 @@ OnFailure=systemd-notifier@%n.service
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/python {{ backup_to_usb_script_path }} {{backup_to_usb_source}} {{backup_to_usb_destination}}
|
||||
ExecStartPost=/bin/systemctl start cleanup-backups.service
|
||||
ExecStartPost=/bin/systemctl start backups-cleanup.service
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -1,4 +1,4 @@
|
||||
backup_to_usb_script_path: "/usr/local/sbin/backup-data-to-usb.python"
|
||||
backup_to_usb_script_path: "/usr/local/sbin/backup-to-usb.python"
|
||||
backup_to_usb_destination: "{{backup_to_usb_mount}}{{backup_to_usb_destination_subdirectory}}"
|
||||
backups_folder_path: "{{backup_to_usb_destination}}"
|
||||
systemctl_mount_service_name: "{{ backup_to_usb_mount | trim('/') | replace('/', '-') }}.mount"
|
@ -1,4 +1,4 @@
|
||||
# role cleanup-backups-timer
|
||||
# role backups-cleanup-timer
|
||||
|
||||
Cleans up old backups
|
||||
|
6
roles/backups-cleanup-service/handlers/main.yml
Normal file
6
roles/backups-cleanup-service/handlers/main.yml
Normal file
@ -0,0 +1,6 @@
|
||||
- name: "reload backups-cleanup.service"
|
||||
systemd:
|
||||
name: backups-cleanup.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
23
roles/backups-cleanup-service/tasks/main.yml
Normal file
23
roles/backups-cleanup-service/tasks/main.yml
Normal file
@ -0,0 +1,23 @@
|
||||
- name: install lsof and python-psutil
|
||||
community.general.pacman:
|
||||
name:
|
||||
- lsof
|
||||
- python-psutil
|
||||
state: present
|
||||
|
||||
- name: "create {{docker_backups_cleanup}}"
|
||||
file:
|
||||
path: "{{docker_backups_cleanup}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create backups-cleanup.py
|
||||
copy:
|
||||
src: "backups-cleanup.py"
|
||||
dest: "{{docker_backups_cleanup}}backups-cleanup.py"
|
||||
|
||||
- name: create backups-cleanup.service
|
||||
template:
|
||||
src: "backups-cleanup.service.j2"
|
||||
dest: "/etc/systemd/system/backups-cleanup.service"
|
||||
notify: reload backups-cleanup.service
|
@ -4,4 +4,4 @@ OnFailure=systemd-notifier@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/python {{docker_backups_cleanup}}cleanup-backups.py --backups-folder-path {{backups_folder_path}} --maximum-backup-size-percent {{size_percent_maximum_backup}}
|
||||
ExecStart=/usr/bin/python {{docker_backups_cleanup}}backups-cleanup.py --backups-folder-path {{backups_folder_path}} --maximum-backup-size-percent {{size_percent_maximum_backup}}
|
1
roles/backups-cleanup-service/vars/main.yml
Normal file
1
roles/backups-cleanup-service/vars/main.yml
Normal file
@ -0,0 +1 @@
|
||||
docker_backups_cleanup: "{{path_administrator_scripts}}backups-cleanup/"
|
@ -1,3 +1,3 @@
|
||||
# role cleanup-backups-timer
|
||||
# role backups-cleanup-timer
|
||||
|
||||
Timer for cleaning up old backups
|
@ -1,6 +1,6 @@
|
||||
- name: "restart cleanup-backups.timer"
|
||||
- name: "restart backups-cleanup.timer"
|
||||
systemd:
|
||||
name: cleanup-backups.timer
|
||||
name: backups-cleanup.timer
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
2
roles/backups-cleanup-timer/meta/main.yml
Normal file
2
roles/backups-cleanup-timer/meta/main.yml
Normal file
@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- backups-cleanup-service
|
5
roles/backups-cleanup-timer/tasks/main.yml
Normal file
5
roles/backups-cleanup-timer/tasks/main.yml
Normal file
@ -0,0 +1,5 @@
|
||||
- name: create backups-cleanup.timer
|
||||
template:
|
||||
src: "backups-cleanup.timer.j2"
|
||||
dest: "/etc/systemd/system/backups-cleanup.timer"
|
||||
notify: restart backups-cleanup.timer
|
@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description=starts cleanup-backups.service
|
||||
Description=starts backups-cleanup.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{on_calendar_backups_cleanup}}
|
@ -1,4 +1,4 @@
|
||||
# role backup-remote-to-local
|
||||
# role backups-consumer
|
||||
|
||||
## goal
|
||||
This script allows to pull backups from a remote server.
|
||||
@ -15,17 +15,17 @@ To track what the service is doing execute one of the following commands:
|
||||
|
||||
#### systemctl
|
||||
```bash
|
||||
watch -n2 "systemctl status backup-remote-to-local.service"
|
||||
watch -n2 "systemctl status pull-remote-backups.service"
|
||||
```
|
||||
|
||||
#### journalctl
|
||||
```bash
|
||||
journalctl -fu backup-remote-to-local.service
|
||||
journalctl -fu pull-remote-backups.service
|
||||
```
|
||||
|
||||
### history
|
||||
```bash
|
||||
sudo journalctl -u backup-remote-to-local
|
||||
sudo journalctl -u pull-remote-backups
|
||||
```
|
||||
|
||||
## see
|
11
roles/backups-consumer/handlers/main.yml
Normal file
11
roles/backups-consumer/handlers/main.yml
Normal file
@ -0,0 +1,11 @@
|
||||
- name: "reload pull-remote-backups service"
|
||||
systemd:
|
||||
name: pull-remote-backups.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
- name: "restart pull-remote-backups timer"
|
||||
systemd:
|
||||
name: pull-remote-backups.timer
|
||||
state: started
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
5
roles/backups-consumer/meta/main.yml
Normal file
5
roles/backups-consumer/meta/main.yml
Normal file
@ -0,0 +1,5 @@
|
||||
dependencies:
|
||||
- git
|
||||
- systemd_notifier
|
||||
- backups-cleanup-timer
|
||||
- docker-volume-backup-cleanup
|
26
roles/backups-consumer/tasks/main.yml
Normal file
26
roles/backups-consumer/tasks/main.yml
Normal file
@ -0,0 +1,26 @@
|
||||
- name: "create {{docker_pull_primary_backups_folder}}"
|
||||
file:
|
||||
path: "{{docker_pull_primary_backups_folder}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create pull-remote-backup.sh
|
||||
copy:
|
||||
src: pull-remote-backup.sh
|
||||
dest: "{{docker_pull_primary_backups_folder}}pull-remote-backup.sh"
|
||||
mode: 0755
|
||||
|
||||
- name: create pull-remote-backups.service
|
||||
template: src=pull-remote-backups.service.j2 dest=/etc/systemd/system/pull-remote-backups.service
|
||||
notify: reload pull-remote-backups service
|
||||
|
||||
- name: create pull-remote-backups.timer
|
||||
template: src=pull-remote-backups.timer.j2 dest=/etc/systemd/system/pull-remote-backups.timer
|
||||
notify: restart pull-remote-backups timer
|
||||
|
||||
- name: create pull-remote-backups.sh
|
||||
template:
|
||||
src: pull-remote-backups.sh.j2
|
||||
dest: "{{docker_pull_primary_backups_folder}}pull-remote-backups.sh"
|
||||
mode: 0755
|
||||
|
@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=pull remote backups
|
||||
OnFailure=systemd-notifier@%n.service docker-volume-backup-cleanup.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/bash {{docker_pull_primary_backups_folder}}pull-remote-backups.sh
|
@ -3,6 +3,6 @@
|
||||
hosts="{{pull_remote_backups}}";
|
||||
errors=0
|
||||
for host in $hosts; do
|
||||
bash {{docker_pull_primary_backups_folder}}backup-remote-to-local.sh $host || ((errors+=1));
|
||||
bash {{docker_pull_primary_backups_folder}}pull-remote-backup.sh $host || ((errors+=1));
|
||||
done;
|
||||
exit $errors;
|
@ -12,8 +12,8 @@ hashed_machine_id="$($get_hashed_machine_id | head -c 64)"
|
||||
get_backup_types="find /Backups/$hashed_machine_id/ -maxdepth 1 -type d -execdir basename {} ;";
|
||||
|
||||
|
||||
# @todo This configuration is not scalable yet. If other backup services then backup-docker-to-local are integrated, this logic needs to be optimized
|
||||
get_version_directories="ls -d /Backups/$hashed_machine_id/backup-docker-to-local/*"
|
||||
# @todo This configuration is not scalable yet. If other backup services then docker-volume-backup are integrated, this logic needs to be optimized
|
||||
get_version_directories="ls -d /Backups/$hashed_machine_id/docker-volume-backup/*"
|
||||
last_version_directory="$($get_version_directories | tail -1)"
|
||||
rsync_command="sudo rsync --server --sender -blogDtpre.iLsfxCIvu . $last_version_directory/"
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
dependencies:
|
||||
- backups-provider-user
|
||||
- cleanup-backups-timer
|
||||
- backups-cleanup-timer
|
||||
|
@ -1,4 +1,4 @@
|
||||
# health-btrfs
|
||||
# btrfs-health-check
|
||||
|
||||
Sends a health report
|
||||
|
12
roles/btrfs-health-check/handlers/main.yml
Normal file
12
roles/btrfs-health-check/handlers/main.yml
Normal file
@ -0,0 +1,12 @@
|
||||
- name: "reload btrfs-health-check.service"
|
||||
systemd:
|
||||
name: btrfs-health-check.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
- name: "restart btrfs-health-check.timer"
|
||||
systemd:
|
||||
name: btrfs-health-check.timer
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
22
roles/btrfs-health-check/tasks/main.yml
Normal file
22
roles/btrfs-health-check/tasks/main.yml
Normal file
@ -0,0 +1,22 @@
|
||||
- name: "create {{docker_btrfs_health_check_folder}}"
|
||||
file:
|
||||
path: "{{docker_btrfs_health_check_folder}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create btrfs-health-check.sh
|
||||
copy:
|
||||
src: btrfs-health-check.sh
|
||||
dest: "{{docker_btrfs_health_check_folder}}btrfs-health-check.sh"
|
||||
|
||||
- name: create btrfs-health-check.service
|
||||
template:
|
||||
src: btrfs-health-check.service.j2
|
||||
dest: /etc/systemd/system/btrfs-health-check.service
|
||||
notify: reload btrfs-health-check.service
|
||||
|
||||
- name: create btrfs-health-check.timer
|
||||
template:
|
||||
src: btrfs-health-check.timer.j2
|
||||
dest: "/etc/systemd/system/btrfs-health-check.timer"
|
||||
notify: restart btrfs-health-check.timer
|
@ -4,4 +4,4 @@ OnFailure=systemd-notifier@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash {{docker_btrfs_health_check_folder}}health-btrfs.sh
|
||||
ExecStart=/bin/bash {{docker_btrfs_health_check_folder}}btrfs-health-check.sh
|
@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description=starts health-btrfs.service
|
||||
Description=starts btrfs-health-check.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{on_calendar_btrfs_health_check}}
|
@ -1 +1 @@
|
||||
docker_btrfs_health_check_folder: "{{path_administrator_scripts}}health-btrfs/"
|
||||
docker_btrfs_health_check_folder: "{{path_administrator_scripts}}btrfs-health-check/"
|
@ -13,6 +13,4 @@
|
||||
template:
|
||||
src: certbot.timer.j2
|
||||
dest: /etc/systemd/system/certbot.timer
|
||||
register: certbot_timer
|
||||
changed_when: certbot_timer.changed or activate_all_timers | default(false) | bool
|
||||
notify: restart certbot timer
|
||||
|
@ -1,6 +0,0 @@
|
||||
- name: "reload cleanup-backups.service"
|
||||
systemd:
|
||||
name: cleanup-backups.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -1,23 +0,0 @@
|
||||
- name: install lsof and python-psutil
|
||||
community.general.pacman:
|
||||
name:
|
||||
- lsof
|
||||
- python-psutil
|
||||
state: present
|
||||
|
||||
- name: "create {{docker_backups_cleanup}}"
|
||||
file:
|
||||
path: "{{docker_backups_cleanup}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create cleanup-backups.py
|
||||
copy:
|
||||
src: "cleanup-backups.py"
|
||||
dest: "{{docker_backups_cleanup}}cleanup-backups.py"
|
||||
|
||||
- name: create cleanup-backups.service
|
||||
template:
|
||||
src: "cleanup-backups.service.j2"
|
||||
dest: "/etc/systemd/system/cleanup-backups.service"
|
||||
notify: reload cleanup-backups.service
|
@ -1 +0,0 @@
|
||||
docker_backups_cleanup: "{{path_administrator_scripts}}cleanup-backups/"
|
@ -1,2 +0,0 @@
|
||||
dependencies:
|
||||
- cleanup-backups-service
|
@ -1,7 +0,0 @@
|
||||
- name: create cleanup-backups.timer
|
||||
template:
|
||||
src: "cleanup-backups.timer.j2"
|
||||
dest: "/etc/systemd/system/cleanup-backups.timer"
|
||||
register: cleanup_backups_timer
|
||||
changed_when: cleanup_backups_timer.changed or activate_all_timers | default(false) | bool
|
||||
notify: restart cleanup-backups.timer
|
@ -1,12 +0,0 @@
|
||||
- name: "reload cleanup-disc-space.service"
|
||||
systemd:
|
||||
name: cleanup-disc-space.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
- name: "restart cleanup-disc-space.timer"
|
||||
systemd:
|
||||
name: cleanup-disc-space.timer
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -1,24 +0,0 @@
|
||||
- name: "create {{free_disc_space_folder}}"
|
||||
file:
|
||||
path: "{{free_disc_space_folder}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create cleanup-disc-space.sh
|
||||
template:
|
||||
src: cleanup-disc-space.sh.j2
|
||||
dest: "{{free_disc_space_folder}}cleanup-disc-space.sh"
|
||||
|
||||
- name: create cleanup-disc-space.service
|
||||
template:
|
||||
src: cleanup-disc-space.service.j2
|
||||
dest: /etc/systemd/system/cleanup-disc-space.service
|
||||
notify: reload cleanup-disc-space.service
|
||||
|
||||
- name: create cleanup-disc-space.timer
|
||||
template:
|
||||
src: cleanup-disc-space.timer.j2
|
||||
dest: /etc/systemd/system/cleanup-disc-space.timer
|
||||
register: cleanup_disc_space_timer
|
||||
changed_when: cleanup_disc_space_timer.changed or activate_all_timers | default(false) | bool
|
||||
notify: restart cleanup-disc-space.timer
|
@ -1 +0,0 @@
|
||||
free_disc_space_folder: "{{path_administrator_scripts}}cleanup-disc-space/"
|
@ -1,3 +0,0 @@
|
||||
# Docker Volume Backup Cleanup
|
||||
This script cleans up failed docker backups.
|
||||
It uses https://github.com/kevinveenbirkenbach/cleanup-failed-docker-backups as base.
|
@ -1,5 +0,0 @@
|
||||
- name: "reload cleanup-failed-docker-backups.service daemon"
|
||||
systemd:
|
||||
name: cleanup-failed-docker-backups.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -1,18 +0,0 @@
|
||||
- name: pull cleanup-failed-docker-backups.git
|
||||
git:
|
||||
repo: "https://github.com/kevinveenbirkenbach/cleanup-failed-docker-backups.git"
|
||||
dest: "{{docker_volume_backup_cleanup_folder}}"
|
||||
update: yes
|
||||
register: git_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: Warn if repo is not reachable
|
||||
debug:
|
||||
msg: "Warning: Repository is not reachable."
|
||||
when: git_result.failed
|
||||
|
||||
- name: configure cleanup-failed-docker-backups.service
|
||||
template:
|
||||
src: cleanup-failed-docker-backups.service.j2
|
||||
dest: /etc/systemd/system/cleanup-failed-docker-backups.service
|
||||
notify: reload cleanup-failed-docker-backups.service daemon
|
@ -1,2 +1,2 @@
|
||||
# health-disc-space
|
||||
# disc-space-check
|
||||
Checks if enough disc space is free
|
12
roles/disc-space-check/handlers/main.yml
Normal file
12
roles/disc-space-check/handlers/main.yml
Normal file
@ -0,0 +1,12 @@
|
||||
- name: "reload disc-space-check.service"
|
||||
systemd:
|
||||
name: disc-space-check.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
- name: "restart disc-space-check.timer"
|
||||
systemd:
|
||||
name: disc-space-check.timer
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
22
roles/disc-space-check/tasks/main.yml
Normal file
22
roles/disc-space-check/tasks/main.yml
Normal file
@ -0,0 +1,22 @@
|
||||
- name: "create {{disc_space_check_folder}}"
|
||||
file:
|
||||
path: "{{disc_space_check_folder}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create disc-space-check.sh
|
||||
copy:
|
||||
src: disc-space-check.sh
|
||||
dest: "{{disc_space_check_folder}}disc-space-check.sh"
|
||||
|
||||
- name: create disc-space-check.service
|
||||
template:
|
||||
src: disc-space-check.service.j2
|
||||
dest: /etc/systemd/system/disc-space-check.service
|
||||
notify: reload disc-space-check.service
|
||||
|
||||
- name: create disc-space-check.timer
|
||||
template:
|
||||
src: disc-space-check.timer.j2
|
||||
dest: /etc/systemd/system/disc-space-check.timer
|
||||
notify: restart disc-space-check.timer
|
@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=checking disc space
|
||||
OnFailure=systemd-notifier@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash {{disc_space_check_folder}}disc-space-check.sh {{size_percent_disc_space_warning}}
|
@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description=starts health-disc-space.service
|
||||
Description=starts disc-space-check.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{on_calendar_disc_space_check}}
|
1
roles/disc-space-check/vars/main.yml
Normal file
1
roles/disc-space-check/vars/main.yml
Normal file
@ -0,0 +1 @@
|
||||
disc_space_check_folder: "{{path_administrator_scripts}}disc-space-check/"
|
@ -81,7 +81,7 @@ docker-compose build &&
|
||||
docker-compose -p akaunting up -d --force-recreate
|
||||
|
||||
# recover all volumes
|
||||
cd {{path_administrator_scripts}}backup-docker-to-local &&
|
||||
cd {{path_administrator_scripts}}docker-volume-backup &&
|
||||
bash docker-volume-recover.sh akaunting_akaunting-modules ${machine_id:0:64} "$backup_version" &&
|
||||
bash docker-volume-recover.sh akaunting_akaunting-data ${machine_id:0:64} "$backup_version" &&
|
||||
bash docker-volume-recover.sh akaunting_akaunting-db ${machine_id:0:64} "$backup_version" akaunting-db "$akaunting_db_password" akaunting
|
||||
|
@ -1,2 +1,2 @@
|
||||
# heal-docker
|
||||
# docker-compose-restart-unhealthy
|
||||
docker-compose restart for containers which are unhealty or excited
|
@ -27,17 +27,16 @@ def print_bash(command):
|
||||
return output
|
||||
|
||||
waiting_time=600
|
||||
blocker_running=True
|
||||
while blocker_running:
|
||||
backup_running=True
|
||||
while backup_running:
|
||||
try:
|
||||
bash("systemctl is-active --quiet backup-docker-to-local.service")
|
||||
bash("systemctl is-active --quiet update-docker.service")
|
||||
bash("systemctl is-active --quiet docker-volume-backup.service")
|
||||
print("backup is running.")
|
||||
print("trying again in " + str(waiting_time) + " seconds.")
|
||||
time.sleep(waiting_time)
|
||||
except:
|
||||
blocker_running=False
|
||||
print("No blocking service is running.")
|
||||
backup_running=False
|
||||
print("no backup is running.")
|
||||
|
||||
unhealthy_container_names=print_bash('docker ps --filter health=unhealthy --format \'{{.Names}}\'')
|
||||
exited_container_names=print_bash('docker ps --filter status=exited --format \'{{.Names}}\'')
|
12
roles/docker-compose-restart-unhealthy/handlers/main.yml
Normal file
12
roles/docker-compose-restart-unhealthy/handlers/main.yml
Normal file
@ -0,0 +1,12 @@
|
||||
- name: "reload docker-compose-restart-unhealthy.service"
|
||||
systemd:
|
||||
name: docker-compose-restart-unhealthy.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
- name: "restart docker-compose-restart-unhealthy.timer"
|
||||
systemd:
|
||||
name: docker-compose-restart-unhealthy.timer
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
22
roles/docker-compose-restart-unhealthy/tasks/main.yml
Normal file
22
roles/docker-compose-restart-unhealthy/tasks/main.yml
Normal file
@ -0,0 +1,22 @@
|
||||
- name: "create {{docker_compose_restart_unhealthy}}"
|
||||
file:
|
||||
path: "{{docker_compose_restart_unhealthy}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create docker-compose-restart-unhealthy.py
|
||||
copy:
|
||||
src: docker-compose-restart-unhealthy.py
|
||||
dest: "{{docker_compose_restart_unhealthy}}docker-compose-restart-unhealthy.py"
|
||||
|
||||
- name: create docker-compose-restart-unhealthy.service
|
||||
template:
|
||||
src: docker-compose-restart-unhealthy.service.j2
|
||||
dest: /etc/systemd/system/docker-compose-restart-unhealthy.service
|
||||
notify: reload docker-compose-restart-unhealthy.service
|
||||
|
||||
- name: create docker-compose-restart-unhealthy.timer
|
||||
template:
|
||||
src: docker-compose-restart-unhealthy.timer.j2
|
||||
dest: "/etc/systemd/system/docker-compose-restart-unhealthy.timer"
|
||||
notify: restart docker-compose-restart-unhealthy.timer
|
@ -4,4 +4,4 @@ OnFailure=systemd-notifier@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/python {{docker_compose_restart_unhealthy}}heal-docker.py
|
||||
ExecStart=/bin/python {{docker_compose_restart_unhealthy}}docker-compose-restart-unhealthy.py
|
@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description=starts heal-docker.service
|
||||
Description=starts docker-compose-restart-unhealthy.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{on_calendar_docker_compose_restart_unhealthy}}
|
@ -1 +1 @@
|
||||
docker_compose_restart_unhealthy: "{{path_administrator_scripts}}heal-docker/"
|
||||
docker_compose_restart_unhealthy: "{{path_administrator_scripts}}docker-compose-restart-unhealthy/"
|
12
roles/docker-health-check/handlers/main.yml
Normal file
12
roles/docker-health-check/handlers/main.yml
Normal file
@ -0,0 +1,12 @@
|
||||
- name: "reload docker-health-check.service"
|
||||
systemd:
|
||||
name: docker-health-check.service
|
||||
state: reloaded
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
- name: "restart docker-health-check.timer"
|
||||
systemd:
|
||||
name: docker-health-check.timer
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
20
roles/docker-health-check/tasks/main.yml
Normal file
20
roles/docker-health-check/tasks/main.yml
Normal file
@ -0,0 +1,20 @@
|
||||
- name: "create {{docker_health_check_folder}}"
|
||||
file:
|
||||
path: "{{docker_health_check_folder}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create docker-health-check.sh
|
||||
copy:
|
||||
src: docker-health-check.sh
|
||||
dest: "{{docker_health_check_folder}}docker-health-check.sh"
|
||||
|
||||
- name: create docker-health-check.service
|
||||
template: src=docker-health-check.service.j2 dest=/etc/systemd/system/docker-health-check.service
|
||||
notify: reload docker-health-check.service
|
||||
|
||||
- name: create docker-health-check.timer
|
||||
template:
|
||||
src: docker-health-check.timer.j2
|
||||
dest: "/etc/systemd/system/docker-health-check.timer"
|
||||
notify: restart docker-health-check.timer
|
@ -4,4 +4,4 @@ OnFailure=systemd-notifier@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash {{docker_health_check_folder}}health-docker.sh
|
||||
ExecStart=/bin/bash {{docker_health_check_folder}}docker-health-check.sh
|
@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description=starts health-docker.service
|
||||
Description=starts docker-health-check.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{on_calendar_docker_health_check}}
|
1
roles/docker-health-check/vars/main.yml
Normal file
1
roles/docker-health-check/vars/main.yml
Normal file
@ -0,0 +1 @@
|
||||
docker_health_check_folder: "{{path_administrator_scripts}}docker-health-check/"
|
@ -60,6 +60,4 @@
|
||||
template:
|
||||
src: "deploy-letsencrypt-mailu.timer.j2"
|
||||
dest: "/etc/systemd/system/deploy-letsencrypt-mailu.timer"
|
||||
register: deploy_letsencrypt_mailu_timer
|
||||
changed_when: deploy_letsencrypt_mailu_timer.changed or activate_all_timers | default(false) | bool
|
||||
notify: restart deploy-letsencrypt-mailu.timer
|
@ -59,8 +59,8 @@ and disable the not functioning apps.
|
||||
```bash
|
||||
cd {{path_docker_compose_files}}nextcloud &&
|
||||
docker-compose down &&
|
||||
docker-compose exec -i database mysql -u nextcloud -pPASSWORT nextcloud < "/Backups/$(sha256sum /etc/machine-id | head -c 64)/backup-docker-to-local/latest/nextcloud_database/sql/backup.sql" &&
|
||||
cd {{path_administrator_scripts}}backup-docker-to-local &&
|
||||
docker-compose exec -i database mysql -u nextcloud -pPASSWORT nextcloud < "/Backups/$(sha256sum /etc/machine-id | head -c 64)/docker-volume-backup/latest/nextcloud_database/sql/backup.sql" &&
|
||||
cd {{path_administrator_scripts}}docker-volume-backup &&
|
||||
bash ./docker-volume-recover.sh "nextcloud_data" "$(sha256sum /etc/machine-id | head -c 64)"
|
||||
```
|
||||
|
||||
|
3
roles/docker-volume-backup-cleanup/README.md
Normal file
3
roles/docker-volume-backup-cleanup/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Docker Volume Backup Cleanup
|
||||
This script cleans up failed docker backups.
|
||||
It uses https://github.com/kevinveenbirkenbach/docker-volume-backup-cleanup as base.
|
5
roles/docker-volume-backup-cleanup/handlers/main.yml
Normal file
5
roles/docker-volume-backup-cleanup/handlers/main.yml
Normal file
@ -0,0 +1,5 @@
|
||||
- name: "reload docker-volume-backup-cleanup.service daemon"
|
||||
systemd:
|
||||
name: docker-volume-backup-cleanup.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
18
roles/docker-volume-backup-cleanup/tasks/main.yml
Normal file
18
roles/docker-volume-backup-cleanup/tasks/main.yml
Normal file
@ -0,0 +1,18 @@
|
||||
- name: pull docker-volume-backup-cleanup.git
|
||||
git:
|
||||
repo: "https://github.com/kevinveenbirkenbach/docker-volume-backup-cleanup.git"
|
||||
dest: "{{docker_volume_backup_cleanup_folder}}"
|
||||
update: yes
|
||||
register: git_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: Warn if repo is not reachable
|
||||
debug:
|
||||
msg: "Warning: Repository is not reachable."
|
||||
when: git_result.failed
|
||||
|
||||
- name: configure docker-volume-backup-cleanup.service
|
||||
template:
|
||||
src: docker-volume-backup-cleanup.service.j2
|
||||
dest: /etc/systemd/system/docker-volume-backup-cleanup.service
|
||||
notify: reload docker-volume-backup-cleanup.service daemon
|
@ -1 +1 @@
|
||||
docker_volume_backup_cleanup_folder: "{{path_administrator_scripts}}cleanup-failed-docker-backups/"
|
||||
docker_volume_backup_cleanup_folder: "{{path_administrator_scripts}}docker-volume-backup-cleanup/"
|
12
roles/docker-volume-backup/handlers/main.yml
Normal file
12
roles/docker-volume-backup/handlers/main.yml
Normal file
@ -0,0 +1,12 @@
|
||||
- name: "reload docker-volume-backup.service"
|
||||
systemd:
|
||||
name: docker-volume-backup.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
|
||||
- name: "restart docker-volume-backup.timer"
|
||||
systemd:
|
||||
name: docker-volume-backup.timer
|
||||
state: started
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
@ -2,4 +2,4 @@ dependencies:
|
||||
- git
|
||||
- backups-provider
|
||||
- systemd_notifier
|
||||
- cleanup-failed-docker-backups
|
||||
- docker-volume-backup-cleanup
|
36
roles/docker-volume-backup/tasks/main.yml
Normal file
36
roles/docker-volume-backup/tasks/main.yml
Normal file
@ -0,0 +1,36 @@
|
||||
- name: install pandas system wide
|
||||
community.general.pacman:
|
||||
name:
|
||||
- lsof
|
||||
- python-pandas
|
||||
state: present
|
||||
|
||||
- name: pull docker-volume-backup.git
|
||||
git:
|
||||
repo: "https://github.com/kevinveenbirkenbach/docker-volume-backup.git"
|
||||
dest: "{{docker_volume_backup_folder}}"
|
||||
update: yes
|
||||
register: git_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: Warn if repo is not reachable
|
||||
debug:
|
||||
msg: "Warning: Repository is not reachable."
|
||||
when: git_result.failed
|
||||
|
||||
- name: configure docker-volume-backup.service
|
||||
template:
|
||||
src: docker-volume-backup.service.j2
|
||||
dest: /etc/systemd/system/docker-volume-backup.service
|
||||
notify: reload docker-volume-backup.service
|
||||
|
||||
- name: configure docker-volume-backup.timer.tpl
|
||||
template: src=docker-volume-backup.timer.j2 dest=/etc/systemd/system/docker-volume-backup.timer
|
||||
notify: restart docker-volume-backup.timer
|
||||
|
||||
- name: create {{docker_volume_backup_folder}}databases.csv
|
||||
copy:
|
||||
src: "{{ inventory_dir }}/files/{{ inventory_hostname }}{{docker_volume_backup_folder}}databases.csv"
|
||||
dest: "{{docker_volume_backup_folder}}databases.csv"
|
||||
owner: root
|
||||
group: root
|
@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=docker volume backup
|
||||
OnFailure=systemd-notifier@%n.service docker-volume-backup-cleanup.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/python {{docker_volume_backup_folder}}docker-volume-backup.py
|
1
roles/docker-volume-backup/vars/main.yml
Normal file
1
roles/docker-volume-backup/vars/main.yml
Normal file
@ -0,0 +1 @@
|
||||
docker_volume_backup_folder: "{{path_administrator_scripts}}docker-volume-backup/"
|
@ -1,5 +1,5 @@
|
||||
dependencies:
|
||||
- backup-docker-to-local
|
||||
- docker-volume-backup
|
||||
- user-administrator
|
||||
- health-docker
|
||||
- heal-docker
|
||||
- docker-health-check
|
||||
- docker-compose-restart-unhealthy
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user