239 lines
7.7 KiB
Bash
Executable File
239 lines
7.7 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Production Setup Script
|
|
# Quick setup for production deployment
|
|
#
|
|
|
|
set -e
|
|
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
echo -e "${BLUE}"
|
|
echo "=========================================="
|
|
echo " Movie Scheduler - Production Setup"
|
|
echo "=========================================="
|
|
echo -e "${NC}"
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -eq 0 ]; then
|
|
echo -e "${RED}Please don't run as root. Run as your regular user.${NC}"
|
|
echo "The script will use sudo when needed."
|
|
exit 1
|
|
fi
|
|
|
|
# Detect deployment method
|
|
echo "Choose deployment method:"
|
|
echo "1) Systemd service (bare metal)"
|
|
echo "2) Docker container"
|
|
read -p "Enter choice [1-2]: " DEPLOY_METHOD
|
|
|
|
if [ "$DEPLOY_METHOD" == "1" ]; then
|
|
echo -e "${GREEN}Setting up systemd service...${NC}"
|
|
|
|
# Check dependencies
|
|
echo "Checking dependencies..."
|
|
for cmd in python3 ffmpeg git sqlite3 systemctl; do
|
|
if ! command -v $cmd &> /dev/null; then
|
|
echo -e "${RED}✗ Missing: $cmd${NC}"
|
|
echo "Install it with: sudo apt-get install $cmd"
|
|
exit 1
|
|
else
|
|
echo -e "${GREEN}✓ Found: $cmd${NC}"
|
|
fi
|
|
done
|
|
|
|
# Check whisper.cpp
|
|
if ! command -v whisper.cpp &> /dev/null; then
|
|
echo -e "${YELLOW}⚠ whisper.cpp not found${NC}"
|
|
read -p "Install whisper.cpp now? [y/N]: " INSTALL_WHISPER
|
|
if [[ $INSTALL_WHISPER =~ ^[Yy]$ ]]; then
|
|
echo "Installing whisper.cpp..."
|
|
git clone https://github.com/ggerganov/whisper.cpp.git /tmp/whisper.cpp
|
|
cd /tmp/whisper.cpp
|
|
make
|
|
sudo cp main /usr/local/bin/whisper.cpp
|
|
sudo chmod +x /usr/local/bin/whisper.cpp
|
|
rm -rf /tmp/whisper.cpp
|
|
echo -e "${GREEN}✓ whisper.cpp installed${NC}"
|
|
fi
|
|
fi
|
|
|
|
# Create scheduler user
|
|
if ! id -u scheduler &> /dev/null; then
|
|
echo "Creating scheduler user..."
|
|
sudo useradd -r -s /bin/bash -d /opt/scheduler -m scheduler
|
|
sudo usermod -aG video,render scheduler
|
|
echo -e "${GREEN}✓ User created${NC}"
|
|
else
|
|
echo -e "${GREEN}✓ User already exists${NC}"
|
|
fi
|
|
|
|
# Create directories
|
|
echo "Creating directories..."
|
|
sudo mkdir -p /opt/scheduler /opt/models
|
|
sudo mkdir -p /mnt/storage/raw_movies /mnt/storage/final_movies
|
|
sudo chown scheduler:scheduler /opt/scheduler
|
|
sudo chown scheduler:scheduler /mnt/storage/raw_movies /mnt/storage/final_movies
|
|
|
|
# Copy application files
|
|
echo "Copying application files..."
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
|
|
|
sudo -u scheduler cp "$PROJECT_DIR/agent.py" /opt/scheduler/
|
|
sudo -u scheduler cp "$PROJECT_DIR/requirements.txt" /opt/scheduler/
|
|
|
|
# Create virtual environment
|
|
echo "Setting up Python virtual environment..."
|
|
sudo -u scheduler python3 -m venv /opt/scheduler/venv
|
|
sudo -u scheduler /opt/scheduler/venv/bin/pip install --upgrade pip
|
|
sudo -u scheduler /opt/scheduler/venv/bin/pip install -r /opt/scheduler/requirements.txt
|
|
|
|
# Download whisper model if needed
|
|
if [ ! -f "/opt/models/ggml-base.bin" ]; then
|
|
echo "Downloading whisper model..."
|
|
sudo wget -q -O /opt/models/ggml-base.bin \
|
|
https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin
|
|
echo -e "${GREEN}✓ Model downloaded${NC}"
|
|
fi
|
|
|
|
# Create config directory
|
|
echo "Setting up configuration..."
|
|
sudo mkdir -p /etc/scheduler
|
|
|
|
# Create environment file
|
|
if [ ! -f "/etc/scheduler/scheduler.env" ]; then
|
|
cat << 'EOF' | sudo tee /etc/scheduler/scheduler.env > /dev/null
|
|
# NocoDB Configuration
|
|
NOCODB_URL=https://your-nocodb.com/api/v2/tables/YOUR_TABLE_ID/records
|
|
NOCODB_TOKEN=YOUR_TOKEN_HERE
|
|
|
|
# RTMP Server
|
|
RTMP_SERVER=rtmp://your-rtmp-server.com/live/stream
|
|
|
|
# Storage Paths
|
|
RAW_DIR=/mnt/storage/raw_movies
|
|
FINAL_DIR=/mnt/storage/final_movies
|
|
|
|
# Whisper Model
|
|
WHISPER_MODEL=/opt/models/ggml-base.bin
|
|
|
|
# VAAPI Device
|
|
VAAPI_DEVICE=/dev/dri/renderD128
|
|
|
|
# Timing
|
|
NOCODB_SYNC_INTERVAL_SECONDS=60
|
|
WATCHDOG_CHECK_INTERVAL_SECONDS=10
|
|
STREAM_GRACE_PERIOD_MINUTES=15
|
|
EOF
|
|
sudo chmod 600 /etc/scheduler/scheduler.env
|
|
sudo chown scheduler:scheduler /etc/scheduler/scheduler.env
|
|
|
|
echo -e "${YELLOW}⚠ IMPORTANT: Edit /etc/scheduler/scheduler.env with your actual values${NC}"
|
|
echo " sudo nano /etc/scheduler/scheduler.env"
|
|
fi
|
|
|
|
# Install systemd service
|
|
echo "Installing systemd service..."
|
|
sudo cp "$PROJECT_DIR/scheduler.service" /etc/systemd/system/
|
|
sudo sed -i 's|^Environment=|# Environment=|g' /etc/systemd/system/scheduler.service
|
|
sudo sed -i 's|^# EnvironmentFile=|EnvironmentFile=|g' /etc/systemd/system/scheduler.service
|
|
sudo systemctl daemon-reload
|
|
|
|
echo ""
|
|
echo -e "${GREEN}=== Installation Complete ===${NC}"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. Edit configuration:"
|
|
echo " sudo nano /etc/scheduler/scheduler.env"
|
|
echo ""
|
|
echo "2. Enable and start service:"
|
|
echo " sudo systemctl enable scheduler"
|
|
echo " sudo systemctl start scheduler"
|
|
echo ""
|
|
echo "3. Check status:"
|
|
echo " sudo systemctl status scheduler"
|
|
echo ""
|
|
echo "4. View logs:"
|
|
echo " sudo journalctl -u scheduler -f"
|
|
|
|
elif [ "$DEPLOY_METHOD" == "2" ]; then
|
|
echo -e "${GREEN}Setting up Docker deployment...${NC}"
|
|
|
|
# Check docker
|
|
if ! command -v docker &> /dev/null; then
|
|
echo -e "${RED}✗ Docker not found${NC}"
|
|
echo "Install Docker first: https://docs.docker.com/get-docker/"
|
|
exit 1
|
|
fi
|
|
|
|
# Check docker compose
|
|
if ! docker compose version &> /dev/null && ! docker-compose --version &> /dev/null; then
|
|
echo -e "${RED}✗ Docker Compose not found${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
|
|
|
# Create deployment directory
|
|
read -p "Installation directory [/opt/scheduler]: " INSTALL_DIR
|
|
INSTALL_DIR=${INSTALL_DIR:-/opt/scheduler}
|
|
|
|
sudo mkdir -p "$INSTALL_DIR"
|
|
sudo chown $USER:$USER "$INSTALL_DIR"
|
|
|
|
# Copy files
|
|
echo "Copying files..."
|
|
cp "$PROJECT_DIR/agent.py" "$INSTALL_DIR/"
|
|
cp "$PROJECT_DIR/requirements.txt" "$INSTALL_DIR/"
|
|
cp "$PROJECT_DIR/Dockerfile" "$INSTALL_DIR/"
|
|
cp "$PROJECT_DIR/docker-compose.prod.yml" "$INSTALL_DIR/"
|
|
|
|
# Create environment file
|
|
if [ ! -f "$INSTALL_DIR/.env.production" ]; then
|
|
cp "$PROJECT_DIR/.env.production.example" "$INSTALL_DIR/.env.production"
|
|
echo -e "${YELLOW}⚠ Edit $INSTALL_DIR/.env.production with your actual values${NC}"
|
|
fi
|
|
|
|
# Create storage directories
|
|
sudo mkdir -p /mnt/storage/raw_movies /mnt/storage/final_movies
|
|
sudo mkdir -p /opt/models
|
|
|
|
# Download whisper model
|
|
if [ ! -f "/opt/models/ggml-base.bin" ]; then
|
|
echo "Downloading whisper model..."
|
|
sudo wget -q -O /opt/models/ggml-base.bin \
|
|
https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin
|
|
echo -e "${GREEN}✓ Model downloaded${NC}"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${GREEN}=== Installation Complete ===${NC}"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. Edit configuration:"
|
|
echo " nano $INSTALL_DIR/.env.production"
|
|
echo ""
|
|
echo "2. Build and start:"
|
|
echo " cd $INSTALL_DIR"
|
|
echo " docker compose -f docker-compose.prod.yml up -d"
|
|
echo ""
|
|
echo "3. View logs:"
|
|
echo " docker compose -f docker-compose.prod.yml logs -f"
|
|
echo ""
|
|
echo "4. Check status:"
|
|
echo " docker compose -f docker-compose.prod.yml ps"
|
|
|
|
else
|
|
echo -e "${RED}Invalid choice${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${BLUE}See PRODUCTION.md for complete documentation${NC}"
|