mirror of
https://github.com/pacnpal/simpleguardhome.git
synced 2025-12-20 04:21:13 -05:00
feat(docker): add health check script and update Dockerfile and .dockerignore for improved backup verification and monitoring
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
# Critical system files (REQUIRED)
|
# Critical system files (REQUIRED)
|
||||||
!requirements.txt
|
!requirements.txt
|
||||||
!docker-entrypoint.sh
|
!docker-entrypoint.sh
|
||||||
|
!healthcheck.py
|
||||||
|
|
||||||
# VERIFICATION: Required files that MUST exist:
|
# VERIFICATION: Required files that MUST exist:
|
||||||
# - src/simpleguardhome/__init__.py
|
# - src/simpleguardhome/__init__.py
|
||||||
@@ -21,6 +22,7 @@
|
|||||||
# - src/simpleguardhome/config.py
|
# - src/simpleguardhome/config.py
|
||||||
# - src/simpleguardhome/templates/index.html
|
# - src/simpleguardhome/templates/index.html
|
||||||
# - src/simpleguardhome/favicon.ico
|
# - src/simpleguardhome/favicon.ico
|
||||||
|
# - healthcheck.py
|
||||||
|
|
||||||
# SAFETY: Never include these files even if allowed above
|
# SAFETY: Never include these files even if allowed above
|
||||||
**/__pycache__/
|
**/__pycache__/
|
||||||
|
|||||||
62
Dockerfile
62
Dockerfile
@@ -51,64 +51,12 @@ RUN echo "Creating verified backups..." && \
|
|||||||
echo "✓ Created and verified $backup"; \
|
echo "✓ Created and verified $backup"; \
|
||||||
done
|
done
|
||||||
|
|
||||||
# STEP 4: Create monitoring scripts
|
# STEP 4: Create monitoring script
|
||||||
RUN echo 'import os,sys,psutil,time,json,logging\nwhile True:\n stats={"cpu":psutil.cpu_percent(),"mem":psutil.virtual_memory().percent,"disk":psutil.disk_usage("/").percent}\n for backup in ["main","backup1","backup2","backup3","backup4","rescue","emergency","last_resort","ultrabackup"]:\n if not os.path.exists(f"/app/{backup}/src/simpleguardhome"): stats[f"{backup}_missing"]=True\n with open("/app/monitor/stats.json","w") as f: json.dump(stats,f)\n time.sleep(5)' > /app/monitor/monitor.py && \
|
RUN echo 'import os,sys,psutil,time,json,logging\nwhile True:\n stats={"cpu":psutil.cpu_percent(),"mem":psutil.virtual_memory().percent,"disk":psutil.disk_usage("/").percent}\n for backup in ["main","backup1","backup2","backup3","backup4","rescue","emergency","last_resort","ultrabackup"]:\n if not os.path.exists(f"/app/{backup}/src/simpleguardhome"): stats[f"{backup}_missing"]=True\n with open("/app/monitor/stats.json","w") as f: json.dump(stats,f)\n time.sleep(5)' > /app/monitor/monitor.py && \
|
||||||
chmod +x /app/monitor/monitor.py
|
chmod +x /app/monitor/monitor.py
|
||||||
|
|
||||||
# STEP 5: Create health check that verifies EVERYTHING
|
# STEP 5: Set up health check script
|
||||||
COPY - <<'EOF' /usr/local/bin/healthcheck.py
|
COPY healthcheck.py /usr/local/bin/
|
||||||
import os, sys, psutil, requests, hashlib, json
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
def verify_all_backups():
|
|
||||||
errors = []
|
|
||||||
backups = ['main', 'backup1', 'backup2', 'backup3', 'backup4',
|
|
||||||
'rescue', 'emergency', 'last_resort', 'ultrabackup']
|
|
||||||
|
|
||||||
# Check each backup
|
|
||||||
for backup in backups:
|
|
||||||
base = f'/app/{backup}/src/simpleguardhome'
|
|
||||||
if not os.path.exists(base):
|
|
||||||
errors.append(f'{backup} backup missing!')
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Verify checksums
|
|
||||||
with open(f'/app/{backup}/checksums.md5') as f:
|
|
||||||
for line in f:
|
|
||||||
checksum, file = line.strip().split()
|
|
||||||
file_path = os.path.join('/app', file)
|
|
||||||
if os.path.exists(file_path):
|
|
||||||
with open(file_path, 'rb') as f:
|
|
||||||
if hashlib.md5(f.read()).hexdigest() != checksum:
|
|
||||||
errors.append(f'Checksum mismatch in {backup}: {file}')
|
|
||||||
else:
|
|
||||||
errors.append(f'File missing in {backup}: {file}')
|
|
||||||
|
|
||||||
# Check monitoring
|
|
||||||
try:
|
|
||||||
with open('/app/monitor/stats.json') as f:
|
|
||||||
stats = json.load(f)
|
|
||||||
if stats['cpu'] > 90 or stats['mem'] > 90 or stats['disk'] > 90:
|
|
||||||
errors.append(f'Resource usage too high: CPU={stats["cpu"]}%, MEM={stats["mem"]}%, DISK={stats["disk"]}%')
|
|
||||||
except:
|
|
||||||
errors.append('Monitoring system failure!')
|
|
||||||
|
|
||||||
return errors
|
|
||||||
|
|
||||||
def main():
|
|
||||||
errors = verify_all_backups()
|
|
||||||
if errors:
|
|
||||||
print('❌ HEALTH CHECK FAILED:')
|
|
||||||
for error in errors:
|
|
||||||
print(f' • {error}')
|
|
||||||
sys.exit(1)
|
|
||||||
print('✅ ALL SYSTEMS OPERATIONAL')
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
EOF
|
|
||||||
|
|
||||||
RUN chmod +x /usr/local/bin/healthcheck.py
|
RUN chmod +x /usr/local/bin/healthcheck.py
|
||||||
|
|
||||||
# Add health check
|
# Add health check
|
||||||
@@ -150,5 +98,9 @@ RUN echo "=== 🚀 ULTRA FINAL VERIFICATION ===" && \
|
|||||||
done && \
|
done && \
|
||||||
echo "✅ EVERYTHING IS VERIFIED, BACKED UP, AND MONITORED!"
|
echo "✅ EVERYTHING IS VERIFIED, BACKED UP, AND MONITORED!"
|
||||||
|
|
||||||
|
# Copy entrypoint script
|
||||||
|
COPY docker-entrypoint.sh /usr/local/bin/
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||||
|
|
||||||
# Start monitoring and application
|
# Start monitoring and application
|
||||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||||
63
healthcheck.py
Normal file
63
healthcheck.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import psutil
|
||||||
|
import requests
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
def verify_all_backups():
|
||||||
|
errors = []
|
||||||
|
backups = ['main', 'backup1', 'backup2', 'backup3', 'backup4',
|
||||||
|
'rescue', 'emergency', 'last_resort', 'ultrabackup']
|
||||||
|
|
||||||
|
# Check each backup
|
||||||
|
for backup in backups:
|
||||||
|
base = f'/app/{backup}/src/simpleguardhome'
|
||||||
|
if not os.path.exists(base):
|
||||||
|
errors.append(f'{backup} backup missing!')
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Verify checksums
|
||||||
|
try:
|
||||||
|
with open(f'/app/{backup}/checksums.md5') as f:
|
||||||
|
for line in f:
|
||||||
|
checksum, file = line.strip().split()
|
||||||
|
file_path = os.path.join('/app', file)
|
||||||
|
if os.path.exists(file_path):
|
||||||
|
with open(file_path, 'rb') as f:
|
||||||
|
if hashlib.md5(f.read()).hexdigest() != checksum:
|
||||||
|
errors.append(f'Checksum mismatch in {backup}: {file}')
|
||||||
|
else:
|
||||||
|
errors.append(f'File missing in {backup}: {file}')
|
||||||
|
except Exception as e:
|
||||||
|
errors.append(f'Failed to verify {backup}: {str(e)}')
|
||||||
|
|
||||||
|
# Check monitoring
|
||||||
|
try:
|
||||||
|
with open('/app/monitor/stats.json') as f:
|
||||||
|
stats = json.load(f)
|
||||||
|
if stats['cpu'] > 90 or stats['mem'] > 90 or stats['disk'] > 90:
|
||||||
|
errors.append(f'Resource usage too high: CPU={stats["cpu"]}%, MEM={stats["mem"]}%, DISK={stats["disk"]}%')
|
||||||
|
except Exception as e:
|
||||||
|
errors.append(f'Monitoring system failure: {str(e)}')
|
||||||
|
|
||||||
|
return errors
|
||||||
|
|
||||||
|
def main():
|
||||||
|
try:
|
||||||
|
errors = verify_all_backups()
|
||||||
|
if errors:
|
||||||
|
print('❌ HEALTH CHECK FAILED:')
|
||||||
|
for error in errors:
|
||||||
|
print(f' • {error}')
|
||||||
|
sys.exit(1)
|
||||||
|
print('✅ ALL SYSTEMS OPERATIONAL')
|
||||||
|
sys.exit(0)
|
||||||
|
except Exception as e:
|
||||||
|
print(f'💥 FATAL ERROR: {str(e)}')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user