mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-29 16:01:04 +01:00
Added disc-space-checker
This commit is contained in:
parent
9313cac2b6
commit
33a7b3c3c1
@ -3,8 +3,13 @@
|
||||
|
||||
on_calendar_btrfs_health_check: "*-*-* 00:00:00"
|
||||
on_calendar_journalctl_health_check: "*-*-* 00:00:00"
|
||||
on_calendar_disc_space_check: "*-*-* 06,12,18,00:00:00"
|
||||
on_calendar_docker_health_check: "*-*-* 09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,00,01,02:00:00"
|
||||
on_calendar_backups_cleanup: "*-*-* 06,12,18,00:30:00"
|
||||
on_calendar_docker_volume_backup: "*-*-* 03:30:00"
|
||||
on_calendar_docker_compose_restart_unhealthy: "*-*-* 09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,00,01:30:00"
|
||||
on_calendar_pull_primary_backups: "*-*-* 21:30:00"
|
||||
|
||||
# Space Variables
|
||||
size_percent_maximum_backup: 75
|
||||
size_percent_disc_space_warning: 85
|
@ -6,6 +6,7 @@
|
||||
- system-security
|
||||
- system-update
|
||||
- native-journalctl
|
||||
- native-disc-space-check
|
||||
#- native-hostname
|
||||
- name: setup btrfs health check
|
||||
hosts: btrfs_health_check_hosts
|
||||
|
@ -5,7 +5,7 @@ import os
|
||||
backup_disk_path = "{{backup_disk_path}}"
|
||||
backups_folder_path = os.path.join(backup_disk_path, "Backups/")
|
||||
deleted = True
|
||||
while psutil.disk_usage(backup_disk_path).percent > int({{backup_space_percent}}) and deleted:
|
||||
while psutil.disk_usage(backup_disk_path).percent > int({{size_percent_maximum_backup}}) and deleted:
|
||||
deleted = False
|
||||
print("%d %% of disk %s are used. Freeing space..." % (psutil.disk_usage(backup_disk_path).percent,backup_disk_path))
|
||||
for primary_directory in os.listdir(backups_folder_path):
|
||||
|
2
roles/native-disc-space-check/README.md
Normal file
2
roles/native-disc-space-check/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# disc-space-check
|
||||
Checks if enough disc space is free
|
12
roles/native-disc-space-check/handlers/main.yml
Normal file
12
roles/native-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
|
2
roles/native-disc-space-check/meta/main.yml
Normal file
2
roles/native-disc-space-check/meta/main.yml
Normal file
@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- native-systemd-email
|
22
roles/native-disc-space-check/tasks/main.yml
Normal file
22
roles/native-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
|
||||
template:
|
||||
src: disc-space-check.sh.j2
|
||||
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-email@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash {{disc_space_check_folder}}disc-space-check.sh
|
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
errors=0
|
||||
echo "checking disc space use..."
|
||||
df
|
||||
for disc_use_percent in $(df --output=pcent | sed 1d)
|
||||
do
|
||||
disc_use_percent_number=$(echo "$disc_use_percent" | sed "s/%//")
|
||||
if [ "$disc_use_percent_number" -gt "{{size_percent_disc_space_warning}}" ]; then
|
||||
echo "WARNING: $disc_use_percent_number exceeds the limit of {{size_percent_disc_space_warning}}%."
|
||||
errors+=1;
|
||||
fi
|
||||
done
|
||||
exit $errors;
|
@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=starts disc-space-check.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{on_calendar_disc_space_check}}
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
1
roles/native-disc-space-check/vars/main.yml
Normal file
1
roles/native-disc-space-check/vars/main.yml
Normal file
@ -0,0 +1 @@
|
||||
disc_space_check_folder: "/home/administrator/scripts/disc-space-check/"
|
Loading…
Reference in New Issue
Block a user