fetch_ml/scripts/deployment/setup-auto-cleanup.sh
Jeremie Fraeys 5a19358d00 Organize configs and scripts, create testing protocol
- Reorganize configs into environments/, workers/, deprecated/ folders
- Reorganize scripts into testing/, deployment/, maintenance/, benchmarks/ folders
- Add comprehensive testing guide documentation
- Add new Makefile targets: test-full, test-auth, test-status
- Update script paths in Makefile to match new organization
- Create testing protocol documentation
- Add cleanup status checking functionality

Testing framework now includes:
- Quick authentication tests (make test-auth)
- Full test suite runner (make test-full)
- Cleanup status monitoring (make test-status)
- Comprehensive documentation and troubleshooting guides
2025-12-06 13:08:15 -05:00

90 lines
2.5 KiB
Bash
Executable file

#!/bin/bash
# Setup auto-cleanup service for fetch_ml
# This creates a systemd timer that runs cleanup daily
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_info "Setting up auto-cleanup service..."
# Check if running on macOS or Linux
if [[ "$OSTYPE" == "darwin"* ]]; then
log_info "Detected macOS - setting up launchd agent"
# Create launchd plist
cat > ~/Library/LaunchAgents/com.fetchml.cleanup.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.fetchml.cleanup</string>
<key>ProgramArguments</key>
<array>
<string>$PROJECT_DIR/scripts/cleanup.sh</string>
<string>--force</string>
</array>
<key>StartInterval</key>
<integer>86400</integer>
<key>RunAtLoad</key>
<false/>
<key>StandardOutPath</key>
<string>/tmp/fetchml-cleanup.log</string>
<key>StandardErrorPath</key>
<string>/tmp/fetchml-cleanup.error.log</string>
</dict>
</plist>
EOF
# Load the launchd agent
launchctl load ~/Library/LaunchAgents/com.fetchml.cleanup.plist
log_success "Auto-cleanup service installed for macOS"
log_info "Logs will be in /tmp/fetchml-cleanup.log"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
log_info "Detected Linux - setting up systemd timer"
# Copy service files
sudo cp "$SCRIPT_DIR/auto-cleanup.service" /etc/systemd/system/
sudo cp "$SCRIPT_DIR/auto-cleanup.timer" /etc/systemd/system/
# Reload systemd and enable timer
sudo systemctl daemon-reload
sudo systemctl enable auto-cleanup.timer
sudo systemctl start auto-cleanup.timer
log_success "Auto-cleanup service installed for Linux"
log_info "Check status with: systemctl status auto-cleanup.timer"
else
echo "Unsupported OS: $OSTYPE"
exit 1
fi
log_info "Auto-cleanup will run daily"
log_info "To uninstall:"
if [[ "$OSTYPE" == "darwin"* ]]; then
echo " launchctl unload ~/Library/LaunchAgents/com.fetchml.cleanup.plist"
echo " rm ~/Library/LaunchAgents/com.fetchml.cleanup.plist"
else
echo " sudo systemctl stop auto-cleanup.timer"
echo " sudo systemctl disable auto-cleanup.timer"
echo " sudo rm /etc/systemd/system/auto-cleanup.*"
fi