vidrip/stop-production.sh

85 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
################################################################################
# VidRip Production Stop Script
################################################################################
# This script safely stops the VidRip production service
################################################################################
set -e # Exit on error
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
PID_FILE="$SCRIPT_DIR/vidrip.pid"
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
################################################################################
# Stop Service
################################################################################
if [ ! -f "$PID_FILE" ]; then
log_error "No PID file found at $PID_FILE"
log_error "VidRip may not be running or was started manually"
exit 1
fi
PID=$(cat "$PID_FILE")
if ! ps -p "$PID" > /dev/null 2>&1; then
log_error "Process $PID is not running"
log_info "Removing stale PID file..."
rm -f "$PID_FILE"
exit 1
fi
log_info "Stopping VidRip (PID: $PID)..."
# Try graceful shutdown first
kill "$PID"
# Wait up to 10 seconds for graceful shutdown
COUNTER=0
while ps -p "$PID" > /dev/null 2>&1 && [ $COUNTER -lt 10 ]; do
sleep 1
COUNTER=$((COUNTER + 1))
done
# Force kill if still running
if ps -p "$PID" > /dev/null 2>&1; then
log_info "Process did not stop gracefully, forcing shutdown..."
kill -9 "$PID"
sleep 1
fi
# Verify it's stopped
if ps -p "$PID" > /dev/null 2>&1; then
log_error "Failed to stop process $PID"
exit 1
fi
# Remove PID file
rm -f "$PID_FILE"
log_success "VidRip stopped successfully"
exit 0