automa/Makefile
m1ngsama e1e5019097 feat: add infrastructure management commands to Makefile
Enhance Makefile with infrastructure service management:

**New Commands:**
- `network-create`: Create Docker networks (automa-proxy, automa-monitoring)
- `network-remove`: Remove Docker networks
- `infra-up`: Start all infrastructure services (Caddy, monitoring, etc.)
- `infra-down`: Stop all infrastructure services
- `infra-status`: Check status of infrastructure services
- `up`: Start infrastructure + all application services
- `down`: Stop all services + infrastructure

**Command Structure:**
```
make network-create  # Setup networks first
make infra-up        # Start infrastructure
make all-up          # Start applications
# Or simply: make up  (does all above)
```

**Infrastructure Services Managed:**
1. Caddy (reverse proxy)
2. Monitoring stack (Prometheus, Grafana, Loki, Promtail, cAdvisor)
3. Watchtower (auto-updates)
4. Duplicati (backups)
5. Fail2ban (security)

**Improvements:**
- Hierarchical service management (infra → apps)
- Graceful shutdown order (apps → infra)
- Network prerequisites automatically checked
- Enhanced help text with categorized commands
- Consistent error handling

Follows Unix philosophy: compose simple commands for complex workflows.

Refs: #4
2026-01-19 16:32:29 +08:00

287 lines
9.3 KiB
Makefile

# Automa - Unified Makefile
# Provides common operations across all services
.PHONY: help all status up down logs restart clean minecraft teamspeak nextcloud
.PHONY: health health-minecraft health-teamspeak health-nextcloud
.PHONY: backup backup-minecraft backup-teamspeak backup-nextcloud backup-list backup-cleanup
.PHONY: network-create network-remove infra-up infra-down infra-status
# Default target
help:
@echo "Automa - Self-hosted Services Manager"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Setup Commands:"
@echo " network-create Create Docker networks"
@echo " network-remove Remove Docker networks"
@echo ""
@echo "Infrastructure Commands:"
@echo " infra-up Start infrastructure (Caddy, Monitoring, etc.)"
@echo " infra-down Stop infrastructure"
@echo " infra-status Show infrastructure status"
@echo ""
@echo "Global Commands:"
@echo " help Show this help message"
@echo " status Show status of all services"
@echo " up Start infrastructure + all services"
@echo " down Stop all services + infrastructure"
@echo " all-up Start all services only"
@echo " all-down Stop all services only"
@echo " health Run health checks on all services"
@echo " backup Backup all services"
@echo " backup-list List available backups"
@echo " backup-cleanup Remove old backups"
@echo ""
@echo "Service-specific Commands:"
@echo " Minecraft:"
@echo " minecraft-up Start Minecraft server"
@echo " minecraft-down Stop Minecraft server"
@echo " minecraft-logs View Minecraft logs"
@echo " minecraft-restart Restart Minecraft server"
@echo " minecraft-status Show server status"
@echo " minecraft-setup Initialize environment"
@echo " minecraft-mods-download Download mods from Modrinth"
@echo " minecraft-mods-list List installed mods"
@echo " minecraft-mods-update Update all mods"
@echo " minecraft-backup Create full backup"
@echo " minecraft-backup-world Backup world data only"
@echo " minecraft-backup-list List available backups"
@echo " health-minecraft Check Minecraft health"
@echo ""
@echo " TeamSpeak:"
@echo " teamspeak-up Start TeamSpeak server"
@echo " teamspeak-down Stop TeamSpeak server"
@echo " teamspeak-logs View TeamSpeak logs"
@echo " teamspeak-restart Restart TeamSpeak server"
@echo " health-teamspeak Check TeamSpeak health"
@echo ""
@echo " Nextcloud:"
@echo " nextcloud-up Start Nextcloud"
@echo " nextcloud-down Stop Nextcloud"
@echo " nextcloud-logs View Nextcloud logs"
@echo " nextcloud-restart Restart Nextcloud"
@echo " health-nextcloud Check Nextcloud health"
@echo ""
@echo "Utility Commands:"
@echo " check Check prerequisites"
@echo " clean Remove stopped containers and unused volumes"
# Check prerequisites
check:
@echo "Checking prerequisites..."
@command -v docker >/dev/null 2>&1 || { echo "Docker not found. Install: https://docs.docker.com/get-docker/"; exit 1; }
@command -v docker compose >/dev/null 2>&1 || command -v docker-compose >/dev/null 2>&1 || { echo "Docker Compose not found."; exit 1; }
@echo "✓ All prerequisites satisfied"
# Status check for all services
status:
@echo "=== Service Status ==="
@echo ""
@echo "Minecraft:"
@cd minecraft && docker compose ps 2>/dev/null || echo " Not running"
@echo ""
@echo "TeamSpeak:"
@cd teamspeak && docker compose ps 2>/dev/null || echo " Not running"
@echo ""
@echo "Nextcloud:"
@cd nextcloud && docker compose ps 2>/dev/null || echo " Not running"
# Start all services
all-up:
@echo "Starting all services..."
@cd minecraft && docker compose up -d
@cd teamspeak && docker compose up -d
@cd nextcloud && docker compose up -d
@echo "✓ All services started"
# Stop all services
all-down:
@echo "Stopping all services..."
@cd minecraft && docker compose down
@cd teamspeak && docker compose down
@cd nextcloud && docker compose down
@echo "✓ All services stopped"
# Minecraft
minecraft-up:
@cd minecraft && docker compose up -d
@echo "✓ Minecraft server started"
minecraft-down:
@cd minecraft && docker compose down
@echo "✓ Minecraft server stopped"
minecraft-logs:
@cd minecraft && docker compose logs -f
minecraft-restart:
@cd minecraft && docker compose restart
@echo "✓ Minecraft server restarted"
minecraft-status:
@cd minecraft && ./scripts/monitor.sh status
minecraft-setup:
@cd minecraft && ./scripts/setup.sh
minecraft-mods-download:
@cd minecraft && ./scripts/mod-manager.sh download
minecraft-mods-list:
@cd minecraft && ./scripts/mod-manager.sh list
minecraft-mods-update:
@cd minecraft && ./scripts/mod-manager.sh update
minecraft-mods-check:
@cd minecraft && ./scripts/mod-manager.sh check
minecraft-backup:
@cd minecraft && ./scripts/backup.sh backup all
minecraft-backup-world:
@cd minecraft && ./scripts/backup.sh backup world
minecraft-backup-list:
@cd minecraft && ./scripts/backup.sh list
minecraft-backup-cleanup:
@cd minecraft && ./scripts/backup.sh cleanup
# TeamSpeak
teamspeak-up:
@cd teamspeak && docker compose up -d
@echo "✓ TeamSpeak server started"
teamspeak-down:
@cd teamspeak && docker compose down
@echo "✓ TeamSpeak server stopped"
teamspeak-logs:
@cd teamspeak && docker compose logs -f
teamspeak-restart:
@cd teamspeak && docker compose restart
@echo "✓ TeamSpeak server restarted"
# Nextcloud
nextcloud-up:
@cd nextcloud && docker compose up -d
@echo "✓ Nextcloud started"
nextcloud-down:
@cd nextcloud && docker compose down
@echo "✓ Nextcloud stopped"
nextcloud-logs:
@cd nextcloud && docker compose logs -f
nextcloud-restart:
@cd nextcloud && docker compose restart
@echo "✓ Nextcloud restarted"
# Cleanup
clean:
@echo "Cleaning up Docker resources..."
@docker container prune -f
@docker volume prune -f
@echo "✓ Cleanup complete"
# ============================================================================
# Health Check Targets
# ============================================================================
health:
@./bin/healthcheck.sh all
health-minecraft:
@./bin/healthcheck.sh minecraft
health-teamspeak:
@./bin/healthcheck.sh teamspeak
health-nextcloud:
@./bin/healthcheck.sh nextcloud
# ============================================================================
# Backup Targets (using bin/backup.sh)
# ============================================================================
backup:
@./bin/backup.sh backup all
backup-minecraft:
@./bin/backup.sh backup minecraft
backup-teamspeak:
@./bin/backup.sh backup teamspeak
backup-nextcloud:
@./bin/backup.sh backup nextcloud
backup-list:
@./bin/backup.sh list
backup-cleanup:
@./bin/backup.sh cleanup
# ============================================================================
# Network Setup
# ============================================================================
network-create:
@echo "Creating Docker networks..."
@docker network create automa-proxy 2>/dev/null || echo " automa-proxy already exists"
@docker network create automa-monitoring 2>/dev/null || echo " automa-monitoring already exists"
@echo "✓ Networks ready"
network-remove:
@echo "Removing Docker networks..."
@docker network rm automa-proxy automa-monitoring 2>/dev/null || echo " Networks already removed"
@echo "✓ Networks removed"
# ============================================================================
# Infrastructure Targets
# ============================================================================
infra-up: network-create
@echo "Starting infrastructure services..."
@cd infrastructure/caddy && docker compose up -d
@cd infrastructure/monitoring && docker compose up -d
@cd infrastructure/watchtower && docker compose up -d
@cd infrastructure/duplicati && docker compose up -d
@cd infrastructure/fail2ban && docker compose up -d
@echo "✓ Infrastructure started"
infra-down:
@echo "Stopping infrastructure services..."
@cd infrastructure/fail2ban && docker compose down || true
@cd infrastructure/duplicati && docker compose down || true
@cd infrastructure/watchtower && docker compose down || true
@cd infrastructure/monitoring && docker compose down || true
@cd infrastructure/caddy && docker compose down || true
@echo "✓ Infrastructure stopped"
infra-status:
@echo "=== Infrastructure Status ==="
@echo ""
@echo "Caddy:"
@cd infrastructure/caddy && docker compose ps 2>/dev/null || echo " Not running"
@echo ""
@echo "Monitoring:"
@cd infrastructure/monitoring && docker compose ps 2>/dev/null || echo " Not running"
@echo ""
@echo "Watchtower:"
@cd infrastructure/watchtower && docker compose ps 2>/dev/null || echo " Not running"
@echo ""
@echo "Duplicati:"
@cd infrastructure/duplicati && docker compose ps 2>/dev/null || echo " Not running"
@echo ""
@echo "Fail2ban:"
@cd infrastructure/fail2ban && docker compose ps 2>/dev/null || echo " Not running"
# ============================================================================
# Full Stack Management
# ============================================================================
up: infra-up all-up
@echo "✓ Full stack started"
down: all-down infra-down
@echo "✓ Full stack stopped"