vidrip/DEPLOYMENT.md

8.9 KiB

VidRip Production Deployment Guide

This guide covers deploying VidRip in a production environment.

Quick Start (Simple Deployment)

The simplest way to run VidRip in production:

# Make scripts executable (if not already)
chmod +x start-production.sh stop-production.sh

# Start the service (simple mode with nohup)
./start-production.sh

# When prompted, enter your domain name (e.g., vidrip.example.com)
# Or press Enter to skip Caddyfile generation

# Stop the service
./stop-production.sh

OR with systemd (recommended for production):

# Start with systemd (auto-starts on boot, better process management)
sudo ./start-production.sh --systemd

# Stop systemd service
sudo ./stop-production.sh --systemd

The start-production.sh script will:

  • Check system requirements (Node.js 18+, yt-dlp)
  • Install dependencies
  • Build backend and frontend
  • Ask for your domain and auto-generate Caddyfile (if not exists)
  • Deploy frontend to /var/www/vidrip
  • Start the backend server (nohup or systemd)
  • Create log files in logs/ directory
  • Show next steps for Caddy installation

Deployment Modes

Simple Mode (nohup):

  • No sudo required
  • Uses PID file for process management
  • Logs to logs/ directory
  • Good for testing or simple deployments

Systemd Mode (--systemd):

  • Requires sudo
  • Auto-starts on system boot
  • Better process management and monitoring
  • Integration with system logging (journalctl)
  • Recommended for production servers

For a robust production setup, use systemd for process management:

1. Install System Requirements

# Install Node.js 18+ (if not installed)
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

# Install yt-dlp
sudo apt-get install -y python3-pip
pip3 install yt-dlp
# OR
sudo wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp
sudo chmod a+rx /usr/local/bin/yt-dlp

2. Deploy Application Files

# Create application directory
sudo mkdir -p /var/www/vidrip
sudo chown $USER:$USER /var/www/vidrip

# Copy files to production location
cp -r /path/to/vidrip/* /var/www/vidrip/

# Create required directories
sudo mkdir -p /var/log/vidrip
sudo chown www-data:www-data /var/log/vidrip

3. Build the Application

cd /var/www/vidrip

# Install dependencies
npm run install:all

# Build backend
cd backend
npm run build

# Build frontend
cd ../frontend
npm run build

4. Configure Backend (Optional)

Create /var/www/vidrip/backend/.env:

NODE_ENV=production
PORT=3001

5. Setup Systemd Service

# Copy service file
sudo cp /var/www/vidrip/vidrip.service /etc/systemd/system/

# Edit the service file to match your paths and user
sudo nano /etc/systemd/system/vidrip.service

# Reload systemd
sudo systemctl daemon-reload

# Enable service to start on boot
sudo systemctl enable vidrip

# Start service
sudo systemctl start vidrip

# Check status
sudo systemctl status vidrip

6. Setup Web Server (Reverse Proxy)

Choose one of the following options:

Install Caddy:

# Ubuntu/Debian
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

Configure Caddyfile:

If you ran start-production.sh and entered your domain, a Caddyfile was auto-generated for you!

Otherwise, edit the included template:

# Edit Caddyfile
nano Caddyfile

# Change line 21:
# FROM: your-domain.com {
# TO:   yourdomain.com {

Deploy Caddyfile:

# Copy to standard location
sudo cp Caddyfile /etc/caddy/Caddyfile

# Validate configuration
sudo caddy validate --config /etc/caddy/Caddyfile

# Enable and start Caddy
sudo systemctl enable caddy
sudo systemctl start caddy

# Check status
sudo systemctl status caddy

Caddy will automatically obtain and renew SSL certificates from Let's Encrypt!

View logs:

sudo journalctl -u caddy -f

Option B: Nginx

Create /etc/nginx/sites-available/vidrip:

server {
    listen 80;
    server_name your-domain.com;

    # Serve frontend static files
    location / {
        root /var/www/vidrip;
        try_files $uri $uri/ /index.html;
    }

    # Proxy API requests to backend
    location /api/ {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # Note: Video files are now served via /api/videos/:id/stream
    # This handles both local and WebDAV storage automatically

    # Increase upload size if needed
    client_max_body_size 100M;
}

Enable the site:

sudo ln -s /etc/nginx/sites-available/vidrip /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Setup SSL with Let's Encrypt:

sudo apt-get install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com

Note: If using Caddy, SSL is automatic - skip this step!

Systemd Service Management

# Start service
sudo systemctl start vidrip

# Stop service
sudo systemctl stop vidrip

# Restart service
sudo systemctl restart vidrip

# View status
sudo systemctl status vidrip

# View logs
sudo journalctl -u vidrip -f

# View application logs
tail -f /var/log/vidrip/vidrip.log
tail -f /var/log/vidrip/vidrip-error.log

PM2 Alternative (Node.js Process Manager)

If you prefer PM2 over systemd:

# Install PM2 globally
sudo npm install -g pm2

# Start application
cd /var/www/vidrip/backend
pm2 start dist/server.js --name vidrip

# Save PM2 configuration
pm2 save

# Setup PM2 to start on boot
pm2 startup
# Follow the instructions shown

# View logs
pm2 logs vidrip

# Monitor
pm2 monit

# Restart
pm2 restart vidrip

Environment Variables

Configure in /var/www/vidrip/backend/.env:

NODE_ENV=production
PORT=3001

Monitoring and Maintenance

Check Service Health

# Check if backend is running
curl http://localhost:3001/api/config

# Check disk space (downloads can fill up)
df -h /var/www/vidrip/backend/downloads

Log Rotation

Create /etc/logrotate.d/vidrip:

/var/log/vidrip/*.log {
    daily
    rotate 14
    compress
    delaycompress
    notifempty
    create 0640 www-data www-data
    sharedscripts
    postrotate
        systemctl reload vidrip > /dev/null 2>&1 || true
    endscript
}

Backup Strategy

# Backup database
cp /var/www/vidrip/backend/data.db /backups/vidrip-$(date +%Y%m%d).db

# Backup downloads (optional, can be large)
rsync -av /var/www/vidrip/backend/downloads/ /backups/downloads/

Firewall Configuration

# Allow HTTP/HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

# Backend should NOT be exposed directly
# Only accessible via nginx proxy

Troubleshooting

Service won't start

# Check logs
sudo journalctl -u vidrip -n 50

# Check if port is already in use
sudo netstat -tlnp | grep 3001

# Check file permissions
ls -la /var/www/vidrip/backend/dist/server.js

Database locked errors

# Check database permissions
ls -la /var/www/vidrip/backend/data.db

# Ensure only one process is accessing database
ps aux | grep vidrip

yt-dlp issues

# Update yt-dlp
pip3 install --upgrade yt-dlp

# Check if it's in PATH
which yt-dlp

# Test manually
yt-dlp --version

Security Checklist

  • Run backend as non-root user (www-data)
  • Enable firewall (ufw)
  • Setup SSL/TLS certificates
  • Restrict database file permissions
  • Configure nginx security headers
  • Enable log rotation
  • Regular yt-dlp updates
  • Monitor disk space for downloads
  • Setup fail2ban (optional)
  • Regular security updates

Performance Tuning

Download Directory Management

Monitor download directory size:

# Check total size
du -sh /var/www/vidrip/backend/downloads

# Find large files
du -h /var/www/vidrip/backend/downloads/* | sort -rh | head -20

Database Optimization

# Vacuum database periodically
sqlite3 /var/www/vidrip/backend/data.db "VACUUM;"

Updating the Application

# Pull latest code
cd /var/www/vidrip
git pull

# Install dependencies
npm run install:all

# Rebuild backend
cd backend
npm run build

# Rebuild frontend
cd ../frontend
npm run build

# Restart service
sudo systemctl restart vidrip