veo3-report/deploy.sh
Dave Porter d969cc384d Initial commit: VEO3 Usage Report System
- PHP web interface with interactive dashboard
- Python automated email reports with SMTP
- systemd service for 7pm EST daily reports
- Cost tracking at $3.20 per video
- Top 25 users per period (24h, 7d, 30d)
- Complete deployment automation
2026-01-06 17:07:46 -05:00

114 lines
3.1 KiB
Bash
Executable file

#!/bin/bash
# VEO3 Report Deployment Script
# This script deploys the VEO3 report system to a Linux server
set -e # Exit on error
# Configuration
DEPLOY_DIR="/var/www/veo3-report"
SERVICE_USER="www-data"
SERVICE_NAME="veo3-report"
LOG_DIR="/var/log/veo3-report"
echo "========================================"
echo "VEO3 Report System Deployment"
echo "========================================"
echo ""
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "ERROR: This script must be run as root (use sudo)"
exit 1
fi
# Create deployment directory
echo "Creating deployment directory: $DEPLOY_DIR"
mkdir -p "$DEPLOY_DIR"
# Create log directory
echo "Creating log directory: $LOG_DIR"
mkdir -p "$LOG_DIR"
mkdir -p "$DEPLOY_DIR/logs"
# Copy files
echo "Copying application files..."
cp veo3_report.py "$DEPLOY_DIR/"
cp veo3_scheduler.py "$DEPLOY_DIR/"
cp requirements.txt "$DEPLOY_DIR/"
cp .env "$DEPLOY_DIR/"
# Make scripts executable
chmod +x "$DEPLOY_DIR/veo3_scheduler.py"
chmod +x "$DEPLOY_DIR/veo3_report.py"
# Set up Python virtual environment
echo "Setting up Python virtual environment..."
cd "$DEPLOY_DIR"
if [ ! -d "venv" ]; then
python3 -m venv venv
fi
# Install dependencies
echo "Installing Python dependencies..."
"$DEPLOY_DIR/venv/bin/pip" install --upgrade pip
"$DEPLOY_DIR/venv/bin/pip" install -r "$DEPLOY_DIR/requirements.txt"
# Set ownership
echo "Setting file ownership..."
chown -R "$SERVICE_USER:$SERVICE_USER" "$DEPLOY_DIR"
chown -R "$SERVICE_USER:$SERVICE_USER" "$LOG_DIR"
# Set permissions
chmod 600 "$DEPLOY_DIR/.env" # Protect sensitive credentials
# Install systemd service
echo "Installing systemd service..."
# Update service file with correct paths
sed -e "s|/var/www/veo3-report|$DEPLOY_DIR|g" \
-e "s|User=www-data|User=$SERVICE_USER|g" \
-e "s|Group=www-data|Group=$SERVICE_USER|g" \
veo3-report.service > /etc/systemd/system/${SERVICE_NAME}.service
# Reload systemd
echo "Reloading systemd daemon..."
systemctl daemon-reload
# Enable service (start on boot)
echo "Enabling service to start on boot..."
systemctl enable ${SERVICE_NAME}.service
# Start service
echo "Starting service..."
systemctl start ${SERVICE_NAME}.service
# Wait a moment for service to start
sleep 2
# Check service status
echo ""
echo "========================================"
echo "Service Status:"
echo "========================================"
systemctl status ${SERVICE_NAME}.service --no-pager
echo ""
echo "========================================"
echo "Deployment Complete!"
echo "========================================"
echo ""
echo "Service Commands:"
echo " Start: sudo systemctl start ${SERVICE_NAME}"
echo " Stop: sudo systemctl stop ${SERVICE_NAME}"
echo " Restart: sudo systemctl restart ${SERVICE_NAME}"
echo " Status: sudo systemctl status ${SERVICE_NAME}"
echo " Logs: sudo journalctl -u ${SERVICE_NAME} -f"
echo ""
echo "Log Files:"
echo " Service: $LOG_DIR/service.log"
echo " Errors: $LOG_DIR/service-error.log"
echo " Scheduler: $DEPLOY_DIR/logs/veo3_scheduler.log"
echo ""
echo "The report will run automatically at 7:00 PM EST every day."
echo ""