#!/bin/bash

# Service Management Script for Church Song Lyric System

ACTION=$1

case $ACTION in
    start)
        echo "Starting services..."
        sudo systemctl start church-songlyric-backend
        sudo systemctl start nginx
        echo "Services started."
        ;;
    stop)
        echo "Stopping services..."
        sudo systemctl stop church-songlyric-backend
        sudo systemctl stop nginx
        echo "Services stopped."
        ;;
    restart)
        echo "Restarting services..."
        sudo systemctl restart church-songlyric-backend
        sudo systemctl restart nginx
        echo "Services restarted."
        ;;
    status)
        echo "=========================================="
        echo "Backend Service Status:"
        echo "=========================================="
        sudo systemctl status church-songlyric-backend --no-pager
        echo ""
        echo "=========================================="
        echo "Nginx Service Status:"
        echo "=========================================="
        sudo systemctl status nginx --no-pager
        ;;
    logs)
        echo "Backend logs (Ctrl+C to exit):"
        sudo journalctl -u church-songlyric-backend -f
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status|logs}"
        echo ""
        echo "  start   - Start all services"
        echo "  stop    - Stop all services"
        echo "  restart - Restart all services"
        echo "  status  - Show service status"
        echo "  logs    - Show backend logs (live)"
        exit 1
        ;;
esac

exit 0
