#!/bin/bash # URL Tracker Tool V2 - Service Control Script # Usage: ./service-control.sh [start|stop|restart|status|logs|enable|disable] SERVICE_NAME="catch-redirect" case "$1" in start) echo "🚀 Starting URL Tracker Tool V2 service..." systemctl start $SERVICE_NAME sleep 3 systemctl status $SERVICE_NAME --no-pager ;; stop) echo "🛑 Stopping URL Tracker Tool V2 service..." systemctl stop $SERVICE_NAME echo "Service stopped." ;; restart) echo "🔄 Restarting URL Tracker Tool V2 service..." systemctl restart $SERVICE_NAME sleep 3 systemctl status $SERVICE_NAME --no-pager ;; status) echo "📊 URL Tracker Tool V2 service status:" systemctl status $SERVICE_NAME --no-pager echo "" echo "🌐 Service Health Check:" echo "API (port 3334): $(curl -s http://localhost:3334/health | jq -r '.status' 2>/dev/null || echo "Not responding")" echo "Frontend (port 3000): $(curl -s http://localhost:3000 >/dev/null && echo "Running" || echo "Not responding")" ;; logs) echo "📝 Recent service logs:" echo "=== Main Service Log ===" tail -20 /var/log/catch-redirect.log echo "" echo "=== API Log ===" tail -10 /var/log/catch-redirect-api.log 2>/dev/null || echo "No API logs yet" echo "" echo "=== Frontend Log ===" tail -10 /var/log/catch-redirect-frontend.log 2>/dev/null || echo "No frontend logs yet" ;; enable) echo "⚡ Enabling URL Tracker Tool V2 service for auto-start..." systemctl enable $SERVICE_NAME echo "Service will now start automatically on boot." ;; disable) echo "❌ Disabling URL Tracker Tool V2 service auto-start..." systemctl disable $SERVICE_NAME echo "Service will no longer start automatically on boot." ;; *) echo "URL Tracker Tool V2 - Service Control" echo "Usage: $0 [start|stop|restart|status|logs|enable|disable]" echo "" echo "Commands:" echo " start - Start the service" echo " stop - Stop the service" echo " restart - Restart the service" echo " status - Show service status and health check" echo " logs - Show recent service logs" echo " enable - Enable auto-start on boot" echo " disable - Disable auto-start on boot" exit 1 ;; esac