Scripts & Tools

Automation scripts and tools to help you manage, deploy, and maintain your Enterprise AI Chatbot Platform.

Script Location: All scripts are located in the scripts/ directory and are designed to work across different environments.

Development Scripts

start-dev.sh

Development

Starts the development environment with hot reload and debugging enabled.

# Usage
./scripts/start-dev.sh

# What it does
- Builds development Docker image
- Starts PostgreSQL database
- Enables hot reload
- Mounts source code volumes
- Sets up development environment variables

setup-db.sh

Database

Initializes the database with required tables and seed data.

# Usage
./scripts/setup-db.sh

# Options
./scripts/setup-db.sh --reset    # Reset database
./scripts/setup-db.sh --seed     # Add sample data

# What it does
- Creates database if not exists
- Runs migrations
- Sets up initial admin user
- Optionally adds seed data

create-admin.sh

User Management

Creates a new admin user with full platform access.

# Usage
./scripts/create-admin.sh admin@company.com

# Interactive mode
./scripts/create-admin.sh

# What it does
- Prompts for email if not provided
- Creates admin user in database
- Sets appropriate permissions
- Generates initial token budget

Production Scripts

start-prod.sh

Production

Starts the production environment with optimized settings.

# Usage
./scripts/start-prod.sh

# What it does
- Builds optimized production image
- Starts all production services
- Configures Nginx reverse proxy
- Sets up SSL/TLS (if configured)
- Enables health checks and monitoring

backup-db.sh

Backup

Creates automated database backups with compression and rotation.

# Usage
./scripts/backup-db.sh

# Scheduled backup (add to crontab)
0 2 * * * /path/to/scripts/backup-db.sh

# What it does
- Creates timestamped database dump
- Compresses backup file
- Stores in ./backups/ directory
- Rotates old backups (keeps last 7 days)
- Logs backup status

update-app.sh

Maintenance

Updates the application with zero-downtime deployment.

# Usage
./scripts/update-app.sh

# With specific version
./scripts/update-app.sh v2.1.0

# What it does
- Pulls latest code from repository
- Builds new Docker image
- Performs rolling update
- Runs database migrations
- Verifies health checks

Utility Scripts

health-check.sh

Monitoring

Comprehensive health check for all services and dependencies.

# Usage
./scripts/health-check.sh

# Detailed output
./scripts/health-check.sh --verbose

# What it checks
- Application health endpoint
- Database connectivity
- Redis connection (if enabled)
- Disk space usage
- Memory usage
- API provider connectivity

cleanup.sh

Maintenance

Cleans up old Docker images, logs, and temporary files.

# Usage
./scripts/cleanup.sh

# Aggressive cleanup
./scripts/cleanup.sh --force

# What it does
- Removes unused Docker images
- Cleans old log files
- Removes temporary files
- Prunes Docker system
- Frees up disk space

restore-db.sh

Recovery

Restores database from backup file with safety checks.

# Usage
./scripts/restore-db.sh backup-2024-01-01.sql

# Interactive mode with backup selection
./scripts/restore-db.sh

# What it does
- Lists available backups
- Validates backup file
- Creates safety backup before restore
- Restores database from backup
- Verifies restoration success

Configuration Scripts

1 Environment Setup

# setup-env.sh - Interactive environment configuration
./scripts/setup-env.sh

# Prompts for:
- Database credentials
- AI provider API keys
- Admin email
- Domain configuration
- SSL certificate paths

2 SSL Configuration

# setup-ssl.sh - SSL certificate configuration
./scripts/setup-ssl.sh your-domain.com

# Options:
--letsencrypt    # Use Let's Encrypt
--self-signed    # Generate self-signed certificate
--custom         # Use custom certificate files

3 Provider Testing

# test-providers.sh - Test AI provider connections
./scripts/test-providers.sh

# Test specific provider
./scripts/test-providers.sh openai
./scripts/test-providers.sh anthropic

# What it tests:
- API key validity
- Rate limits
- Model availability
- Response time

Monitoring & Logging

Log Management

# View application logs
./scripts/logs.sh app

# View database logs
./scripts/logs.sh db

# Follow logs in real-time
./scripts/logs.sh --follow

# Export logs for analysis
./scripts/logs.sh --export

Usage Analytics

# Generate usage report
./scripts/usage-report.sh

# Monthly report
./scripts/usage-report.sh --month

# Export to CSV
./scripts/usage-report.sh --csv

# Email report
./scripts/usage-report.sh --email admin@company.com

Automation Examples

Cron Job Setup

# Add to crontab for automated tasks
crontab -e

# Daily backup at 2 AM
0 2 * * * /path/to/scripts/backup-db.sh

# Weekly cleanup on Sunday at 3 AM
0 3 * * 0 /path/to/scripts/cleanup.sh

# Hourly health check
0 * * * * /path/to/scripts/health-check.sh --quiet

# Daily usage report
0 9 * * * /path/to/scripts/usage-report.sh --email admin@company.com

CI/CD Integration

# GitHub Actions example
name: Deploy to Production
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Deploy to server
        run: |
          ssh user@server 'cd /app && ./scripts/update-app.sh'
          ssh user@server './scripts/health-check.sh'

Script Customization

Configuration: Most scripts can be customized by editing the configuration section at the top of each file. Common settings include backup retention, log levels, and notification endpoints.

Custom Script Template

#!/bin/bash
# Custom script template

# Configuration
SCRIPT_NAME="custom-script"
LOG_FILE="/var/log/${SCRIPT_NAME}.log"
CONFIG_FILE="./config/script.conf"

# Functions
log() {
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}

check_dependencies() {
    # Check required tools and services
    command -v docker >/dev/null 2>&1 || { log "Docker is required"; exit 1; }
}

main() {
    log "Starting $SCRIPT_NAME"
    check_dependencies
    
    # Your script logic here
    
    log "$SCRIPT_NAME completed successfully"
}

# Run main function
main "$@"
Important: Always test scripts in a development environment before using in production. Make sure to review and understand what each script does before execution.
Scripts Ready! You now have a comprehensive set of tools to manage your Enterprise AI Chatbot Platform efficiently.