add Final Infrastructure Setup

This commit is contained in:
Patryk Hegenberg 2026-03-29 13:45:10 +02:00
commit 7733dde658
174 changed files with 204949 additions and 0 deletions

View file

@ -0,0 +1,29 @@
- name: Kopiere Blackhole Script
template:
src: blackhole.sh.j2
dest: /usr/local/bin/blackhole.sh
mode: "0755"
- name: Deploye Systemd Service für Blackhole
copy:
dest: /etc/systemd/system/blackhole.service
content: |
[Unit]
Description=Thesis Blackhole Service (Cleanup)
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/blackhole.sh
Restart=always
User=root
[Install]
WantedBy=multi-user.target
- name: Starte Blackhole Service
systemd:
name: blackhole
state: started
enabled: yes
daemon_reload: yes

View file

@ -0,0 +1,45 @@
#!/bin/bash
TARGET_DIR="/local_testdata/test-destination"
THRESHOLD=60
TARGET_USAGE=50
SLEEP_INTERVAL=2
DELETE_BATCH=200
SAFE_MINUTES=5
echo "[$(date)] Blackhole Monitor gestartet für $TARGET_DIR"
while true; do
CURRENT_USAGE=$(df -P "$TARGET_DIR" | awk 'NR==2 {print $5}' | tr -d '%')
if (( CURRENT_USAGE > THRESHOLD )); then
echo "[$(date)] Disk usage ${CURRENT_USAGE}% -> starte Cleanup"
while (( CURRENT_USAGE > TARGET_USAGE )); do
find "$TARGET_DIR" \
-type f \
-mmin +$SAFE_MINUTES \
-print0 \
| head -z -n $DELETE_BATCH \
| xargs -0 -r rm -f
CURRENT_USAGE=$(df -P "$TARGET_DIR" | awk 'NR==2 {print $5}' | tr -d '%')
echo "[$(date)] aktuelle Auslastung: ${CURRENT_USAGE}%"
if ! find "$TARGET_DIR" -type f -mmin +$SAFE_MINUTES | head -n 1 | grep -q .; then
echo "[$(date)] Keine alten Dateien mehr zum Löschen"
break
fi
done
echo "[$(date)] Cleanup beendet"
fi
sleep "$SLEEP_INTERVAL"
done