#!/bin/bash # ScriptShare Management Script set -e COMPOSE_FILE="docker-compose.prod.yml" show_help() { echo "ScriptShare Management Script" echo "" echo "Usage: $0 [COMMAND]" echo "" echo "Commands:" echo " start Start all services" echo " stop Stop all services" echo " restart Restart all services" echo " logs Show logs for all services" echo " logs [svc] Show logs for specific service" echo " status Show status of all services" echo " backup Create database backup" echo " restore Restore database from backup" echo " update Update application (pull, build, restart)" echo " clean Clean up unused Docker resources" echo " shell [svc] Open shell in service container" echo " db Connect to database" echo " help Show this help message" echo "" echo "Services: scriptshare-db, scriptshare-api, scriptshare-frontend, scriptshare-proxy, scriptshare-redis" } case "$1" in start) echo "๐Ÿš€ Starting ScriptShare services..." docker-compose -f "$COMPOSE_FILE" up -d echo "โœ… Services started" ;; stop) echo "๐Ÿ›‘ Stopping ScriptShare services..." docker-compose -f "$COMPOSE_FILE" down echo "โœ… Services stopped" ;; restart) echo "๐Ÿ”„ Restarting ScriptShare services..." docker-compose -f "$COMPOSE_FILE" restart echo "โœ… Services restarted" ;; logs) if [ -n "$2" ]; then echo "๐Ÿ“‹ Showing logs for $2..." docker-compose -f "$COMPOSE_FILE" logs -f "$2" else echo "๐Ÿ“‹ Showing logs for all services..." docker-compose -f "$COMPOSE_FILE" logs -f fi ;; status) echo "๐Ÿ“Š Service Status:" docker-compose -f "$COMPOSE_FILE" ps echo "" echo "๐Ÿฅ Health Status:" for service in scriptshare-db scriptshare-api scriptshare-frontend scriptshare-proxy; do health=$(docker inspect --format='{{.State.Health.Status}}' "$service" 2>/dev/null || echo "not found") echo " $service: $health" done ;; backup) echo "๐Ÿ—„๏ธ Creating database backup..." ./scripts/backup.sh ;; restore) if [ -z "$2" ]; then echo "โŒ Please specify backup file to restore" echo "Usage: $0 restore " exit 1 fi echo "๐Ÿ”„ Restoring database from $2..." # Implementation for restore would go here echo "โš ๏ธ Restore functionality not yet implemented" ;; update) echo "๐Ÿ”„ Updating ScriptShare application..." docker-compose -f "$COMPOSE_FILE" pull docker-compose -f "$COMPOSE_FILE" build --no-cache docker-compose -f "$COMPOSE_FILE" up -d echo "โœ… Application updated" ;; clean) echo "๐Ÿงน Cleaning up Docker resources..." docker system prune -f docker volume prune -f echo "โœ… Cleanup completed" ;; shell) if [ -z "$2" ]; then echo "โŒ Please specify service name" echo "Available services: scriptshare-db, scriptshare-api, scriptshare-frontend, scriptshare-proxy" exit 1 fi echo "๐Ÿ’ป Opening shell in $2..." docker-compose -f "$COMPOSE_FILE" exec "$2" /bin/sh ;; db) echo "๐Ÿ—ƒ๏ธ Connecting to database..." if [ -f ".env" ]; then source .env fi docker-compose -f "$COMPOSE_FILE" exec scriptshare-db mysql -u "${DB_USER:-scriptshare_user}" -p"${DB_PASSWORD:-ScriptShare_App_2024_Secure!}" "${DB_NAME:-scriptshare}" ;; help|--help|-h) show_help ;; *) echo "โŒ Unknown command: $1" echo "" show_help exit 1 ;; esac