From 53e70893827d48de03c88247c7625ed45b895f68 Mon Sep 17 00:00:00 2001 From: edwin Date: Wed, 4 Feb 2026 01:42:45 -0800 Subject: [PATCH] First Commit --- CHATWOOT_CONFIG_TROUBLESHOOTING.md | 480 +++++++++++++++++++++++++++++ CHATWOOT_SETUP_GUIDE.md | 282 +++++++++++++++++ README.MD | 15 + chatwoot_install.sh | 472 ++++++++++++++++++++++++++++ chatwoot_quick_install.sh | 146 +++++++++ install_chatwoot.sh | 472 ++++++++++++++++++++++++++++ 6 files changed, 1867 insertions(+) create mode 100644 CHATWOOT_CONFIG_TROUBLESHOOTING.md create mode 100644 CHATWOOT_SETUP_GUIDE.md create mode 100644 README.MD create mode 100644 chatwoot_install.sh create mode 100644 chatwoot_quick_install.sh create mode 100644 install_chatwoot.sh diff --git a/CHATWOOT_CONFIG_TROUBLESHOOTING.md b/CHATWOOT_CONFIG_TROUBLESHOOTING.md new file mode 100644 index 0000000..d360280 --- /dev/null +++ b/CHATWOOT_CONFIG_TROUBLESHOOTING.md @@ -0,0 +1,480 @@ +# Chatwoot Configuration & Troubleshooting Guide + +## Common Environment Variables (.env) + +Edit with: `sudo nano /home/chatwoot/chatwoot/.env` + +### Core Configuration +``` +RAILS_ENV=production # Always use production for live +SECRET_KEY_BASE=your-secret-key # Generated during install +FRONTEND_URL=https://yourdomain.com # Where Chatwoot is accessed from +``` + +### Database Configuration +``` +POSTGRES_HOST=localhost +POSTGRES_PORT=5432 +POSTGRES_USERNAME=chatwoot +POSTGRES_PASSWORD=your_secure_password # IMPORTANT: Change this! +POSTGRES_DATABASE=chatwoot_production +``` + +### Redis Configuration +``` +REDIS_URL=redis://localhost:6379/0 +``` + +### Account Signup +``` +ENABLE_ACCOUNT_SIGNUP=false # true to allow new signups +``` + +### Email Configuration (Choose One) + +**SMTP:** +``` +SMTP_HOST=smtp.gmail.com +SMTP_PORT=587 +SMTP_USERNAME=your-email@gmail.com +SMTP_PASSWORD=your-app-password +SMTP_AUTHENTICATION=plain +SMTP_ENABLE_STARTTLS_AUTO=true +``` + +**Mailgun:** +``` +MAILGUN_SMTP_ENABLED=true +MAILGUN_SMTP_DOMAIN=your-domain.mailgun.org +MAILGUN_SMTP_LOGIN=postmaster@your-domain.mailgun.org +MAILGUN_SMTP_PASSWORD=your-mailgun-key +``` + +### Integrations + +**Facebook:** +``` +FACEBOOK_CHANNEL_ENABLED=true +FACEBOOK_APP_ID=your-app-id +FACEBOOK_APP_SECRET=your-app-secret +``` + +**WhatsApp:** +``` +WHATSAPP_CHANNEL_ENABLED=true +WHATSAPP_API_KEY=your-api-key +``` + +**Google Analytics:** +``` +GOOGLE_ANALYTICS_ID=UA-XXXXXXXX-X +``` + +### Security +``` +ENABLE_ACCOUNT_SIGNUP=false +CORS_ORIGINS=https://yourdomain.com +``` + +## Nginx Configuration Examples + +### Basic HTTP (Port 3000) +```nginx +server { + listen 80; + server_name _; + + location / { + proxy_pass http://127.0.0.1:3000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + 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; + underscores_in_headers on; + } +} +``` + +### HTTPS with Let's Encrypt +```nginx +# Redirect HTTP to HTTPS +server { + listen 80; + server_name yourdomain.com; + return 301 https://$server_name$request_uri; +} + +# HTTPS Server +server { + listen 443 ssl http2; + server_name yourdomain.com; + + ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers HIGH:!aNULL:!MD5; + ssl_prefer_server_ciphers on; + + # Security headers + add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; + add_header X-Content-Type-Options "nosniff" always; + add_header X-Frame-Options "SAMEORIGIN" always; + + location / { + proxy_pass http://127.0.0.1:3000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + 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 https; + proxy_buffering off; + underscores_in_headers on; + } +} +``` + +## Troubleshooting Guide + +### Issue: Chatwoot Won't Start + +**Check Service Status:** +```bash +systemctl status chatwoot-web.target +systemctl status chatwoot-worker.target +``` + +**View Detailed Logs:** +```bash +journalctl -u chatwoot-web.1.service -n 100 +journalctl -u chatwoot-worker.1.service -n 100 +``` + +**Common Causes:** +1. Database connection error - verify PostgreSQL is running +2. Redis unavailable - check Redis service +3. Asset compilation failed - recompile assets +4. Port already in use - check port 3000 + +**Solutions:** +```bash +# Restart PostgreSQL +sudo systemctl restart postgresql + +# Restart Redis +sudo systemctl restart redis-server + +# Recompile assets +cd /home/chatwoot/chatwoot +bundle exec rake assets:precompile RAILS_ENV=production NODE_OPTIONS="--max-old-space-size=4096 --openssl-legacy-provider" + +# Clear Rails cache +cd /home/chatwoot/chatwoot +bundle exec rake cache:clear RAILS_ENV=production +``` + +### Issue: High Memory Usage + +**Check Memory:** +```bash +free -h +top -b -n 1 | head -20 +``` + +**Solutions:** +1. Increase swap space: +```bash +sudo fallocate -l 8G /swapfile +sudo chmod 600 /swapfile +sudo mkswap /swapfile +sudo swapon /swapfile +echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab +``` + +2. Optimize Sidekiq workers in `.env`: +``` +SIDEKIQ_CONCURRENCY=5 +SIDEKIQ_MEMORY_KILLER_MAX_SIZE=800 +``` + +3. Reduce Rails threads: +``` +WEB_CONCURRENCY=2 +MAX_THREADS=4 +``` + +### Issue: Slow Performance + +**Check System Resources:** +```bash +# CPU usage +top +# Disk I/O +iostat -x 1 5 +# Network connections +netstat -an | grep ESTABLISHED +``` + +**Optimization Steps:** + +1. **Database Optimization:** +```bash +# Connect to PostgreSQL +sudo -u postgres psql chatwoot_production + +# Analyze database +ANALYZE; +``` + +2. **Redis Optimization:** +```bash +# Check Redis memory +redis-cli info memory +# Clear Redis cache +redis-cli flushall +``` + +3. **Nginx Optimization:** +```nginx +# Add to http block in nginx.conf +client_max_body_size 20M; +gzip on; +gzip_types text/plain text/css text/javascript application/json application/javascript; +``` + +4. **Scale Sidekiq Workers:** +Edit `/etc/systemd/system/chatwoot-worker.1.service`: +```ini +Environment="SIDEKIQ_CONCURRENCY=10" +ExecStart=/bin/bash -lc 'exec bundle exec sidekiq -c 10 -e $RAILS_ENV' +``` + +### Issue: SSL Certificate Not Renewing + +**Check Certificate Expiry:** +```bash +sudo certbot certificates +``` + +**Manual Renewal:** +```bash +sudo certbot renew --nginx +``` + +**Auto-Renewal Check:** +```bash +sudo systemctl status certbot.timer +sudo systemctl enable certbot.timer +``` + +### Issue: Database Corruption + +**Check Database Health:** +```bash +sudo -u postgres psql chatwoot_production -c "PRAGMA integrity_check;" +``` + +**Restore from Backup:** +```bash +sudo -u postgres dropdb chatwoot_production +sudo -u postgres createdb chatwoot_production -O chatwoot +sudo -u postgres pg_restore -d chatwoot_production /path/to/backup.sql +``` + +### Issue: Email Not Sending + +**Check SMTP Configuration:** +```bash +cd /home/chatwoot/chatwoot +sudo -u chatwoot bundle exec rails console production +``` + +**Test Email:** +```ruby +ActionMailer::Base.mail( + from: 'test@example.com', + to: 'admin@example.com', + subject: 'Test Email', + body: 'This is a test email' +).deliver_now +``` + +### Issue: Agents Can't Login + +**Check Agent Access:** +```bash +cd /home/chatwoot/chatwoot +sudo -u chatwoot bundle exec rails console production + +# Check user +User.find_by(email: 'agent@example.com') + +# Reset password +user = User.find_by(email: 'agent@example.com') +user.update(password: 'newpassword123') +``` + +### Issue: Database Migrations Failed + +**Run Migrations Manually:** +```bash +cd /home/chatwoot/chatwoot +sudo -u chatwoot bundle exec rake db:migrate RAILS_ENV=production +``` + +**Rollback Migration:** +```bash +cd /home/chatwoot/chatwoot +sudo -u chatwoot bundle exec rake db:rollback STEP=1 RAILS_ENV=production +``` + +## Maintenance Tasks + +### Regular Backups +```bash +#!/bin/bash +# Daily backup script + +BACKUP_DIR="/backups/chatwoot" +DATE=$(date +%Y-%m-%d) + +mkdir -p $BACKUP_DIR + +# Database backup +sudo -u postgres pg_dump -Fc chatwoot_production > $BACKUP_DIR/db_$DATE.sql + +# Application backup +tar -czf $BACKUP_DIR/app_$DATE.tar.gz \ + -C /home/chatwoot chatwoot \ + --exclude='*.log' \ + --exclude='tmp/*' \ + --exclude='public/packs/*' + +# Keep only last 30 days +find $BACKUP_DIR -name "*.sql" -mtime +30 -delete +find $BACKUP_DIR -name "*.tar.gz" -mtime +30 -delete +``` + +### Monitor Disk Space +```bash +# Check disk usage +df -h + +# Find large files +du -sh /home/chatwoot/chatwoot/* + +# Clean logs +journalctl --vacuum-time=30d +rm -f /var/log/chatwoot/*.log.* +``` + +### Monitor Services +```bash +#!/bin/bash +# Service monitoring script + +# Check services +systemctl is-active chatwoot-web.target || systemctl restart chatwoot-web.target +systemctl is-active chatwoot-worker.target || systemctl restart chatwoot-worker.target +systemctl is-active postgresql || systemctl restart postgresql +systemctl is-active redis-server || systemctl restart redis-server +systemctl is-active nginx || systemctl restart nginx +``` + +### Update Chatwoot +```bash +cd /home/chatwoot/chatwoot + +# If cwctl is available +cwctl --upgrade + +# Or manual update +git fetch origin +git checkout v3.x.x # Replace with version +bundle install +bundle exec rake db:migrate RAILS_ENV=production +bundle exec rake assets:precompile RAILS_ENV=production NODE_OPTIONS="--max-old-space-size=4096 --openssl-legacy-provider" +systemctl restart chatwoot-web.target chatwoot-worker.target +``` + +## Performance Monitoring + +### Check Active Connections +```bash +# Database connections +sudo -u postgres psql -c "SELECT count(*) FROM pg_stat_activity;" + +# Redis connections +redis-cli CLIENT LIST +``` + +### Monitor CPU and Memory +```bash +# Real-time monitoring +watch -n 1 'top -b -n 1 | head -20' + +# Systemd resource limits +systemctl status chatwoot-web.target --full +``` + +## Security Hardening + +### UFW Firewall Setup +```bash +sudo ufw enable +sudo ufw allow 22/tcp +sudo ufw allow 80/tcp +sudo ufw allow 443/tcp +sudo ufw default deny incoming +sudo ufw default allow outgoing +``` + +### Nginx Security Headers +```nginx +add_header X-Frame-Options "SAMEORIGIN" always; +add_header X-Content-Type-Options "nosniff" always; +add_header X-XSS-Protection "1; mode=block" always; +add_header Referrer-Policy "no-referrer-when-downgrade" always; +add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always; +``` + +### SSH Hardening +```bash +# Edit /etc/ssh/sshd_config +PermitRootLogin no +PasswordAuthentication no +PubkeyAuthentication yes +X11Forwarding no + +# Restart SSH +sudo systemctl restart ssh +``` + +## Useful Commands Quick Reference + +```bash +# View real-time logs +journalctl -f -u chatwoot-web.1.service + +# Restart all services +systemctl restart chatwoot-web.target chatwoot-worker.target + +# Access Rails console +cd /home/chatwoot/chatwoot && sudo -u chatwoot bundle exec rails console production + +# Check Chatwoot version +cd /home/chatwoot/chatwoot && git describe --tags + +# Database status +sudo -u postgres psql -d chatwoot_production -c "\dt" + +# Redis info +redis-cli INFO + +# Check port usage +sudo netstat -tlnp | grep 3000 +``` diff --git a/CHATWOOT_SETUP_GUIDE.md b/CHATWOOT_SETUP_GUIDE.md new file mode 100644 index 0000000..3207dab --- /dev/null +++ b/CHATWOOT_SETUP_GUIDE.md @@ -0,0 +1,282 @@ +# Chatwoot Installation Guide for Ubuntu + +## Overview +This guide covers installing Chatwoot (an open-source customer engagement platform) on Ubuntu 20.04, 22.04, or 24.04 LTS using an automated installation script. + +## Prerequisites + +**System Requirements:** +- Ubuntu 20.04 LTS, 22.04 LTS, or 24.04 LTS +- Minimum 4 cores (8 cores recommended for production) +- Minimum 4GB RAM (8GB or more for production) +- At least 20GB free disk space +- Root or sudo access +- (Optional) A domain name for SSL configuration + +**Open Required Ports:** +- Port 80 (HTTP) +- Port 443 (HTTPS, if using SSL) +- Port 3000 (if accessing directly without reverse proxy) + +## Quick Start + +### 1. Download the Installation Script +```bash +wget https://example.com/chatwoot_install.sh +chmod +x chatwoot_install.sh +``` + +Or clone from GitHub: +```bash +git clone https://github.com/chatwoot/chatwoot.git +cd chatwoot/deployment +sudo bash setup_20.04.sh +``` + +### 2. Run the Installation Script +```bash +sudo bash chatwoot_install.sh +``` + +This will: +- Update system packages +- Install all dependencies (Ruby, Node.js, PostgreSQL, Redis, Nginx) +- Create the chatwoot user +- Clone the Chatwoot repository +- Setup PostgreSQL database +- Install Ruby gems +- Compile assets +- Configure systemd services +- Setup Nginx as a reverse proxy +- Start all services + +The installation typically takes 30-60 minutes. + +### 3. Access Chatwoot +After installation completes, access Chatwoot at: +``` +http://your-server-ip:3000 +``` + +## Configuration with Domain and SSL + +### Using the Installation Script +If you have a domain name and an A record pointing to your server: + +```bash +sudo bash chatwoot_install.sh --ssl --domain yourdomain.com --email admin@yourdomain.com +``` + +This will: +- Configure Nginx for your domain +- Generate SSL certificates using Let's Encrypt +- Enable automatic HTTPS +- Access Chatwoot at `https://yourdomain.com` + +### Manual SSL Configuration +If you prefer manual setup: + +```bash +sudo certbot certonly --nginx -d yourdomain.com +``` + +Then restart Nginx: +```bash +sudo systemctl restart nginx +``` + +## Post-Installation Setup + +### 1. Edit Environment Variables +The `.env` file controls Chatwoot configuration. Update it with your specific settings: + +```bash +sudo nano /home/chatwoot/chatwoot/.env +``` + +Key variables: +- `RAILS_ENV=production` - Environment mode +- `POSTGRES_HOST=localhost` - Database host +- `POSTGRES_USERNAME=chatwoot` - Database user +- `POSTGRES_PASSWORD=` - Database password (change this!) +- `REDIS_URL=redis://localhost:6379` - Redis connection +- `ENABLE_ACCOUNT_SIGNUP=true/false` - Allow new user registration +- `MAILGUN_SMTP_ENABLED=true/false` - Email configuration +- `FACEBOOK_CHANNEL_ENABLED=true/false` - Channel integrations + +### 2. Run Database Migrations +```bash +cd /home/chatwoot/chatwoot +bundle exec rake db:migrate RAILS_ENV=production +``` + +### 3. Create Admin User +```bash +cd /home/chatwoot/chatwoot +bundle exec rake chatwoot:create_account[account_name] +bundle exec rake chatwoot:create_user[email@example.com,admin_name,Admin,password] +``` + +Alternatively, use the web interface to create the first admin user after accessing Chatwoot. + +### 4. Configure Integrations +Log in to the Chatwoot dashboard and configure: +- Email accounts +- Social media channels (Facebook, WhatsApp, Instagram) +- Live chat widget +- Custom API keys + +## Service Management + +### Check Service Status +```bash +systemctl status chatwoot-web.target +systemctl status chatwoot-worker.target +``` + +### View Logs +```bash +# Web service logs +journalctl -u chatwoot-web.1.service -f + +# Worker service logs +journalctl -u chatwoot-worker.1.service -f + +# Installation logs +tail -f /var/log/chatwoot-setup.log +``` + +### Restart Services +```bash +systemctl restart chatwoot-web.target +systemctl restart chatwoot-worker.target +``` + +### Stop Services +```bash +systemctl stop chatwoot-web.target +systemctl stop chatwoot-worker.target +``` + +## Upgrading Chatwoot + +### Using cwctl (Recommended) +```bash +cwctl --upgrade +``` + +### Manual Upgrade +```bash +cd /home/chatwoot/chatwoot +git fetch origin +git checkout v3.x.x # Replace with desired version +bundle install +rake db:migrate RAILS_ENV=production +rake assets:precompile RAILS_ENV=production +systemctl restart chatwoot-web.target chatwoot-worker.target +``` + +## Backup and Restore + +### Create Database Backup +```bash +sudo -u postgres pg_dump -Fc chatwoot_production > chatwoot_backup.sql +``` + +### Restore Database +```bash +sudo -u postgres pg_restore -d chatwoot_production chatwoot_backup.sql +``` + +### Backup Application Files +```bash +tar -czf chatwoot_app_backup.tar.gz /home/chatwoot/chatwoot +``` + +## Troubleshooting + +### Service Won't Start +Check logs for errors: +```bash +journalctl -u chatwoot-web.1.service -n 50 +``` + +### Asset Compilation Issues +Clear compiled assets and recompile: +```bash +cd /home/chatwoot/chatwoot +rm -rf public/packs/* +bundle exec rake assets:precompile RAILS_ENV=production NODE_OPTIONS="--max-old-space-size=4096 --openssl-legacy-provider" +``` + +### Database Connection Issues +Verify PostgreSQL is running: +```bash +systemctl status postgresql +``` + +Check database credentials in `.env` file match PostgreSQL configuration. + +### Out of Memory During Installation +Increase swap space: +```bash +sudo fallocate -l 4G /swapfile +sudo chmod 600 /swapfile +sudo mkswap /swapfile +sudo swapon /swapfile +``` + +## Security Recommendations + +1. **Change Default Passwords** + - Update PostgreSQL password + - Update Redis password + - Create strong admin credentials + +2. **Enable SSL/HTTPS** + - Always use HTTPS in production + - Use valid SSL certificates + - Implement HTTP to HTTPS redirects + +3. **Configure Firewall** + ```bash + sudo ufw enable + sudo ufw allow 22/tcp + sudo ufw allow 80/tcp + sudo ufw allow 443/tcp + ``` + +4. **Regular Updates** + - Keep Ubuntu packages updated: `sudo apt update && sudo apt upgrade` + - Keep Chatwoot updated to latest stable version + - Monitor security advisories + +5. **Database Security** + - Use strong PostgreSQL passwords + - Restrict database access to localhost + - Regular backups with secure storage + +## Additional Resources + +- **Official Documentation:** https://www.chatwoot.com/docs/self-hosted +- **Community Forum:** https://www.chatwoot.com/community +- **GitHub Repository:** https://github.com/chatwoot/chatwoot +- **API Documentation:** https://docs.chatwoot.com/api/inbox + +## Getting Help + +If you encounter issues: + +1. Check the installation logs: `/var/log/chatwoot-setup.log` +2. Review service logs: `journalctl -u chatwoot-* -f` +3. Visit the Chatwoot community forum +4. Check GitHub issues: https://github.com/chatwoot/chatwoot/issues +5. Consult the official documentation + +## Support the Project + +Chatwoot is open-source and maintained by the community. Consider: +- Starring the GitHub repository +- Contributing code or translations +- Supporting the project financially +- Reporting issues and bugs diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..f06fe59 --- /dev/null +++ b/README.MD @@ -0,0 +1,15 @@ +Summary +I've created a complete Chatwoot installation package with four files: +Installation Scripts: + +chatwoot_install.sh - Full-featured script with detailed setup, logs, and modular functions. Best for custom installations. +chatwoot_quick_install.sh - Simplified version using the official Chatwoot installer. Best for quick deployment. + +Documentation: +3. CHATWOOT_SETUP_GUIDE.md - Complete setup instructions covering prerequisites, installation, configuration, service management, upgrades, backups, and troubleshooting basics. +4. CHATWOOT_CONFIG_TROUBLESHOOTING.md - Advanced reference with environment variables, Nginx configs, detailed troubleshooting, maintenance tasks, and performance optimization. +Quick Start: +bashsudo bash chatwoot_quick_install.sh +# or for more control +sudo bash chatwoot_install.sh --ssl --domain yourdomain.com --email admin@yourdomain.com +The scripts support Ubuntu 20.04, 22.04, and 24.04 LTS, handle PostgreSQL/Redis setup, Nginx configuration, SSL with Let's Encrypt, and systemd service management. \ No newline at end of file diff --git a/chatwoot_install.sh b/chatwoot_install.sh new file mode 100644 index 0000000..89c4489 --- /dev/null +++ b/chatwoot_install.sh @@ -0,0 +1,472 @@ +#!/bin/bash + +################################################################################ +# Chatwoot Installation Script for Ubuntu +# Supports: Ubuntu 20.04 LTS, 22.04 LTS, 24.04 LTS +# Description: Automated installation of Chatwoot on Ubuntu +# Usage: sudo bash chatwoot_install.sh +################################################################################ + +set -eu -o pipefail + +# 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 + +# Variables +CHATWOOT_USER="chatwoot" +CHATWOOT_HOME="/home/chatwoot" +CHATWOOT_APP_PATH="${CHATWOOT_HOME}/chatwoot" +RAILS_ENV="production" +RAILS_LOG_DIR="/var/log/chatwoot" +LOG_FILE="/var/log/chatwoot-setup.log" + +# Check if running as root +if [ "$EUID" -ne 0 ]; then + echo -e "${RED}This script must be run as root (use: sudo bash chatwoot_install.sh)${NC}" + exit 1 +fi + +# Functions +log_info() { + echo -e "${BLUE}[INFO]${NC} $1" | tee -a "$LOG_FILE" +} + +log_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" | tee -a "$LOG_FILE" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" | tee -a "$LOG_FILE" +} + +log_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" | tee -a "$LOG_FILE" +} + +# Initialize log file +mkdir -p "$(dirname "$LOG_FILE")" +touch "$LOG_FILE" +log_info "Starting Chatwoot installation script" + +# Function to check command existence +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Function to detect Ubuntu version +detect_ubuntu_version() { + if [ -f /etc/os-release ]; then + . /etc/os-release + UBUNTU_VERSION="$VERSION_ID" + UBUNTU_CODENAME="$VERSION_CODENAME" + log_info "Detected Ubuntu version: $UBUNTU_VERSION ($UBUNTU_CODENAME)" + else + log_error "Unable to detect Ubuntu version" + exit 1 + fi +} + +# Function to update system +update_system() { + log_info "Updating system packages..." + apt-get update -qq + apt-get upgrade -y -qq + log_success "System packages updated" +} + +# Function to install dependencies +install_dependencies() { + log_info "Installing system dependencies..." + + local packages=( + "curl" + "wget" + "git" + "build-essential" + "libssl-dev" + "libreadline-dev" + "zlib1g-dev" + "libsqlite3-dev" + "libxml2-dev" + "libxslt1-dev" + "libcurl4-openssl-dev" + "postgresql" + "postgresql-contrib" + "redis-server" + "nginx" + "certbot" + "python3-certbot-nginx" + "nodejs" + "npm" + ) + + for package in "${packages[@]}"; do + if ! dpkg -l | grep -q "^ii $package"; then + log_info "Installing $package..." + apt-get install -y -qq "$package" || log_warning "Failed to install $package" + fi + done + + log_success "Dependencies installed" +} + +# Function to setup Ruby +setup_ruby() { + log_info "Setting up Ruby environment..." + + # Install RVM + if ! command_exists rvm; then + log_info "Installing RVM..." + gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB 2>/dev/null || true + curl -sSL https://get.rvm.io | bash -s stable >/dev/null 2>&1 + source /etc/profile.d/rvm.sh + fi + + # Install Ruby + log_info "Installing Ruby 3.2..." + source /etc/profile.d/rvm.sh + rvm install ruby-3.2.0 >/dev/null 2>&1 || log_warning "Ruby installation may have issues" + rvm use ruby-3.2.0 --default >/dev/null 2>&1 + + # Install Bundler + gem install bundler --quiet + + log_success "Ruby environment setup complete" +} + +# Function to create chatwoot user and directories +setup_chatwoot_user() { + log_info "Setting up Chatwoot user and directories..." + + if ! id "$CHATWOOT_USER" &>/dev/null; then + useradd -m -s /bin/bash -d "$CHATWOOT_HOME" "$CHATWOOT_USER" + log_info "Created chatwoot user" + fi + + # Create necessary directories + mkdir -p "$RAILS_LOG_DIR" + chown -R "$CHATWOOT_USER:$CHATWOOT_USER" "$RAILS_LOG_DIR" + chmod 755 "$RAILS_LOG_DIR" + + log_success "Chatwoot user and directories created" +} + +# Function to setup PostgreSQL +setup_postgresql() { + log_info "Setting up PostgreSQL database..." + + # Generate secure password + local db_password=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20; echo '') + + # Start PostgreSQL + systemctl start postgresql + systemctl enable postgresql + + # Create database and user + sudo -u postgres psql <&1 | tee -a "$LOG_FILE" + else + log_warning "Chatwoot directory already exists" + fi + + cd "$CHATWOOT_APP_PATH" + + # Checkout latest stable version + log_info "Checking out latest release..." + sudo -u "$CHATWOOT_USER" git fetch --tags 2>&1 | tee -a "$LOG_FILE" + + # Setup environment file + log_info "Setting up environment configuration..." + if [ ! -f "$CHATWOOT_APP_PATH/.env" ]; then + sudo -u "$CHATWOOT_USER" cp "$CHATWOOT_APP_PATH/.env.example" "$CHATWOOT_APP_PATH/.env" + fi + + # Update .env file with database credentials + sudo -u "$CHATWOOT_USER" sed -i 's|POSTGRES_HOST=localhost|POSTGRES_HOST=localhost|g' "$CHATWOOT_APP_PATH/.env" + sudo -u "$CHATWOOT_USER" sed -i 's|POSTGRES_USERNAME=postgres|POSTGRES_USERNAME=chatwoot|g' "$CHATWOOT_APP_PATH/.env" + sudo -u "$CHATWOOT_USER" sed -i 's|POSTGRES_PASSWORD=|POSTGRES_PASSWORD=YOUR_DB_PASSWORD|g' "$CHATWOOT_APP_PATH/.env" + + log_success "Chatwoot repository cloned and configured" +} + +# Function to install Ruby gems +install_gems() { + log_info "Installing Ruby gems (this may take a while)..." + + cd "$CHATWOOT_APP_PATH" + source /etc/profile.d/rvm.sh + + sudo -u "$CHATWOOT_USER" bash -c "cd $CHATWOOT_APP_PATH && rvm use ruby-3.2.0 && bundle install --quiet" 2>&1 | tee -a "$LOG_FILE" + + log_success "Ruby gems installed" +} + +# Function to compile assets +compile_assets() { + log_info "Compiling assets (this may take a while)..." + + cd "$CHATWOOT_APP_PATH" + source /etc/profile.d/rvm.sh + + sudo -u "$CHATWOOT_USER" bash -c "cd $CHATWOOT_APP_PATH && rvm use ruby-3.2.0 && rake assets:precompile RAILS_ENV=production NODE_OPTIONS='--max-old-space-size=4096 --openssl-legacy-provider'" 2>&1 | tee -a "$LOG_FILE" + + log_success "Assets compiled successfully" +} + +# Function to setup systemd services +setup_systemd_services() { + log_info "Setting up systemd services..." + + # Copy service files + cp "$CHATWOOT_APP_PATH/deployment/chatwoot-web.1.service" /etc/systemd/system/ + cp "$CHATWOOT_APP_PATH/deployment/chatwoot-web.target" /etc/systemd/system/ + cp "$CHATWOOT_APP_PATH/deployment/chatwoot-worker.1.service" /etc/systemd/system/ + cp "$CHATWOOT_APP_PATH/deployment/chatwoot-worker.target" /etc/systemd/system/ + + # Update service files for correct user and paths + sed -i "s|User=chatwoot|User=$CHATWOOT_USER|g" /etc/systemd/system/chatwoot-web.1.service + sed -i "s|User=chatwoot|User=$CHATWOOT_USER|g" /etc/systemd/system/chatwoot-worker.1.service + sed -i "s|WorkingDirectory=/home/chatwoot/chatwoot|WorkingDirectory=$CHATWOOT_APP_PATH|g" /etc/systemd/system/chatwoot-web.1.service + sed -i "s|WorkingDirectory=/home/chatwoot/chatwoot|WorkingDirectory=$CHATWOOT_APP_PATH|g" /etc/systemd/system/chatwoot-worker.1.service + + systemctl daemon-reload + systemctl enable chatwoot-web.target + systemctl enable chatwoot-worker.target + + log_success "Systemd services configured" +} + +# Function to start services +start_services() { + log_info "Starting Chatwoot services..." + + systemctl start chatwoot-web.target + systemctl start chatwoot-worker.target + + # Wait for services to start + sleep 5 + + if systemctl is-active --quiet chatwoot-web.target && systemctl is-active --quiet chatwoot-worker.target; then + log_success "Chatwoot services started successfully" + else + log_error "Failed to start Chatwoot services" + log_info "Check logs: journalctl -u chatwoot-web.target -f" + exit 1 + fi +} + +# Function to setup Nginx +setup_nginx() { + log_info "Configuring Nginx as reverse proxy..." + + # Create Nginx configuration + cat > /etc/nginx/sites-available/chatwoot <<'EOF' +server { + listen 80; + server_name _; + + # Point upstream to Chatwoot App Server + set $upstream 127.0.0.1:3000; + + # Nginx strips out underscore in headers by default + # Chatwoot relies on underscore in headers for API + underscores_in_headers on; + + location / { + proxy_pass http://$upstream; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + 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; + proxy_read_timeout 90; + proxy_buffering off; + } +} +EOF + + # Enable site + ln -sf /etc/nginx/sites-available/chatwoot /etc/nginx/sites-enabled/chatwoot + rm -f /etc/nginx/sites-enabled/default + + # Test and reload Nginx + if nginx -t >/dev/null 2>&1; then + systemctl restart nginx + log_success "Nginx configured and restarted" + else + log_error "Nginx configuration error" + nginx -t + exit 1 + fi +} + +# Function to setup SSL with Let's Encrypt +setup_ssl() { + local domain="$1" + local email="$2" + + log_info "Setting up SSL certificate for $domain..." + + certbot certonly --nginx -d "$domain" -m "$email" --agree-tos --non-interactive 2>&1 | tee -a "$LOG_FILE" + + # Update Nginx configuration for HTTPS + cat > /etc/nginx/sites-available/chatwoot </dev/null 2>&1; then + systemctl restart nginx + log_success "SSL certificate installed and Nginx configured" + else + log_error "Nginx configuration error" + exit 1 + fi +} + +# Main installation flow +main() { + log_info "====== Chatwoot Installation Started ======" + + # Detect Ubuntu version + detect_ubuntu_version + + # Check requirements + if ! command_exists curl; then + log_info "Installing curl first..." + apt-get update -qq && apt-get install -y -qq curl + fi + + # Installation steps + update_system + install_dependencies + setup_chatwoot_user + setup_postgresql + setup_redis + setup_ruby + setup_chatwoot + install_gems + compile_assets + setup_systemd_services + start_services + setup_nginx + + # Summary + log_success "====== Chatwoot Installation Complete ======" + echo "" + echo -e "${GREEN}Chatwoot installation completed successfully!${NC}" + echo "" + echo "Access your Chatwoot instance at:" + echo -e "${BLUE} http://$(hostname -I | awk '{print $1}'):3000${NC}" + echo "" + echo "To configure domain and SSL, run:" + echo -e "${BLUE} sudo bash chatwoot_install.sh --ssl --domain yourdomain.com --email your@email.com${NC}" + echo "" + echo "Important next steps:" + echo "1. Update .env file with correct database password" + echo "2. Run database migrations: cd $CHATWOOT_APP_PATH && bundle exec rake db:migrate RAILS_ENV=production" + echo "3. Create admin user and complete initial setup via web interface" + echo "" + echo "For logs, check: journalctl -u chatwoot-web.target -f" + echo "" +} + +# Parse command line arguments +CONFIGURE_SSL=false +DOMAIN="" +EMAIL="" + +while [[ $# -gt 0 ]]; do + case $1 in + --ssl) + CONFIGURE_SSL=true + shift + ;; + --domain) + DOMAIN="$2" + shift 2 + ;; + --email) + EMAIL="$2" + shift 2 + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + +# Run main installation +main + +# Setup SSL if requested +if [ "$CONFIGURE_SSL" = true ]; then + if [ -z "$DOMAIN" ] || [ -z "$EMAIL" ]; then + log_error "Domain and email are required for SSL setup" + exit 1 + fi + setup_ssl "$DOMAIN" "$EMAIL" +fi diff --git a/chatwoot_quick_install.sh b/chatwoot_quick_install.sh new file mode 100644 index 0000000..fdeeb84 --- /dev/null +++ b/chatwoot_quick_install.sh @@ -0,0 +1,146 @@ +#!/bin/bash + +################################################################################ +# Chatwoot Quick Installation Script +# Supports: Ubuntu 20.04, 22.04, 24.04 LTS +# Simple method using official Chatwoot installation script +# Usage: sudo bash chatwoot_quick_install.sh +################################################################################ + +set -e + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +# Check if running as root +if [ "$EUID" -ne 0 ]; then + echo -e "${RED}Error: This script must be run as root${NC}" + echo "Run: sudo bash chatwoot_quick_install.sh" + exit 1 +fi + +echo -e "${GREEN}╔════════════════════════════════════════════╗${NC}" +echo -e "${GREEN}║ Chatwoot Installation - Ubuntu 20.04+ ║${NC}" +echo -e "${GREEN}╚════════════════════════════════════════════╝${NC}" +echo "" + +# Check Ubuntu version +if [ ! -f /etc/os-release ]; then + echo -e "${RED}Error: Cannot detect Ubuntu version${NC}" + exit 1 +fi + +. /etc/os-release +echo -e "${GREEN}[✓]${NC} Ubuntu $VERSION_ID detected" + +# Validate Ubuntu version +case $VERSION_ID in + 20.04|22.04|24.04) + echo -e "${GREEN}[✓]${NC} Supported Ubuntu version" + ;; + *) + echo -e "${YELLOW}[!]${NC} Ubuntu $VERSION_ID is not officially supported" + echo " Supported versions: 20.04, 22.04, 24.04" + read -p "Continue anyway? (y/n) " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi + ;; +esac + +echo "" +read -p "Install Postgres and Redis? (yes/no): " install_postgres_redis +install_postgres_redis=${install_postgres_redis:-yes} + +echo "" +read -p "Configure domain and SSL? (yes/no): " configure_domain +configure_domain=${configure_domain:-no} + +domain="" +email="" + +if [ "$configure_domain" = "yes" ]; then + echo "" + echo "Make sure you have created an A record for your domain" + read -p "Enter your domain (e.g., chatwoot.example.com): " domain + read -p "Enter email for Let's Encrypt: " email + + if [ -z "$domain" ] || [ -z "$email" ]; then + echo -e "${RED}Error: Domain and email are required for SSL${NC}" + configure_domain="no" + fi +fi + +echo "" +echo -e "${YELLOW}Starting installation...${NC}" +echo "" + +# Update system +echo -e "${GREEN}[1/6]${NC} Updating system..." +apt-get update -qq +apt-get upgrade -y -qq + +# Download official Chatwoot installation script +echo -e "${GREEN}[2/6]${NC} Downloading Chatwoot installation script..." +cd /tmp +wget -q https://raw.githubusercontent.com/chatwoot/chatwoot/develop/deployment/setup_20.04.sh -O chatwoot_setup.sh +chmod +x chatwoot_setup.sh + +# Run installation +echo -e "${GREEN}[3/6]${NC} Running Chatwoot installation..." +echo "" + +# Prepare script arguments +install_args="--install" + +if [ "$install_postgres_redis" != "yes" ]; then + install_args="$install_args --web-only" +fi + +# Run the official script with automatic answers +bash ./chatwoot_setup.sh $install_args </dev/null 2>&1 +} + +# Function to detect Ubuntu version +detect_ubuntu_version() { + if [ -f /etc/os-release ]; then + . /etc/os-release + UBUNTU_VERSION="$VERSION_ID" + UBUNTU_CODENAME="$VERSION_CODENAME" + log_info "Detected Ubuntu version: $UBUNTU_VERSION ($UBUNTU_CODENAME)" + else + log_error "Unable to detect Ubuntu version" + exit 1 + fi +} + +# Function to update system +update_system() { + log_info "Updating system packages..." + apt-get update -qq + apt-get upgrade -y -qq + log_success "System packages updated" +} + +# Function to install dependencies +install_dependencies() { + log_info "Installing system dependencies..." + + local packages=( + "curl" + "wget" + "git" + "build-essential" + "libssl-dev" + "libreadline-dev" + "zlib1g-dev" + "libsqlite3-dev" + "libxml2-dev" + "libxslt1-dev" + "libcurl4-openssl-dev" + "postgresql" + "postgresql-contrib" + "redis-server" + "nginx" + "certbot" + "python3-certbot-nginx" + "nodejs" + "npm" + ) + + for package in "${packages[@]}"; do + if ! dpkg -l | grep -q "^ii $package"; then + log_info "Installing $package..." + apt-get install -y -qq "$package" || log_warning "Failed to install $package" + fi + done + + log_success "Dependencies installed" +} + +# Function to setup Ruby +setup_ruby() { + log_info "Setting up Ruby environment..." + + # Install RVM + if ! command_exists rvm; then + log_info "Installing RVM..." + gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB 2>/dev/null || true + curl -sSL https://get.rvm.io | bash -s stable >/dev/null 2>&1 + source /etc/profile.d/rvm.sh + fi + + # Install Ruby + log_info "Installing Ruby 3.2..." + source /etc/profile.d/rvm.sh + rvm install ruby-3.2.0 >/dev/null 2>&1 || log_warning "Ruby installation may have issues" + rvm use ruby-3.2.0 --default >/dev/null 2>&1 + + # Install Bundler + gem install bundler --quiet + + log_success "Ruby environment setup complete" +} + +# Function to create chatwoot user and directories +setup_chatwoot_user() { + log_info "Setting up Chatwoot user and directories..." + + if ! id "$CHATWOOT_USER" &>/dev/null; then + useradd -m -s /bin/bash -d "$CHATWOOT_HOME" "$CHATWOOT_USER" + log_info "Created chatwoot user" + fi + + # Create necessary directories + mkdir -p "$RAILS_LOG_DIR" + chown -R "$CHATWOOT_USER:$CHATWOOT_USER" "$RAILS_LOG_DIR" + chmod 755 "$RAILS_LOG_DIR" + + log_success "Chatwoot user and directories created" +} + +# Function to setup PostgreSQL +setup_postgresql() { + log_info "Setting up PostgreSQL database..." + + # Generate secure password + local db_password=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20; echo '') + + # Start PostgreSQL + systemctl start postgresql + systemctl enable postgresql + + # Create database and user + sudo -u postgres psql <&1 | tee -a "$LOG_FILE" + else + log_warning "Chatwoot directory already exists" + fi + + cd "$CHATWOOT_APP_PATH" + + # Checkout latest stable version + log_info "Checking out latest release..." + sudo -u "$CHATWOOT_USER" git fetch --tags 2>&1 | tee -a "$LOG_FILE" + + # Setup environment file + log_info "Setting up environment configuration..." + if [ ! -f "$CHATWOOT_APP_PATH/.env" ]; then + sudo -u "$CHATWOOT_USER" cp "$CHATWOOT_APP_PATH/.env.example" "$CHATWOOT_APP_PATH/.env" + fi + + # Update .env file with database credentials + sudo -u "$CHATWOOT_USER" sed -i 's|POSTGRES_HOST=localhost|POSTGRES_HOST=localhost|g' "$CHATWOOT_APP_PATH/.env" + sudo -u "$CHATWOOT_USER" sed -i 's|POSTGRES_USERNAME=postgres|POSTGRES_USERNAME=chatwoot|g' "$CHATWOOT_APP_PATH/.env" + sudo -u "$CHATWOOT_USER" sed -i 's|POSTGRES_PASSWORD=|POSTGRES_PASSWORD=YOUR_DB_PASSWORD|g' "$CHATWOOT_APP_PATH/.env" + + log_success "Chatwoot repository cloned and configured" +} + +# Function to install Ruby gems +install_gems() { + log_info "Installing Ruby gems (this may take a while)..." + + cd "$CHATWOOT_APP_PATH" + source /etc/profile.d/rvm.sh + + sudo -u "$CHATWOOT_USER" bash -c "cd $CHATWOOT_APP_PATH && rvm use ruby-3.2.0 && bundle install --quiet" 2>&1 | tee -a "$LOG_FILE" + + log_success "Ruby gems installed" +} + +# Function to compile assets +compile_assets() { + log_info "Compiling assets (this may take a while)..." + + cd "$CHATWOOT_APP_PATH" + source /etc/profile.d/rvm.sh + + sudo -u "$CHATWOOT_USER" bash -c "cd $CHATWOOT_APP_PATH && rvm use ruby-3.2.0 && rake assets:precompile RAILS_ENV=production NODE_OPTIONS='--max-old-space-size=4096 --openssl-legacy-provider'" 2>&1 | tee -a "$LOG_FILE" + + log_success "Assets compiled successfully" +} + +# Function to setup systemd services +setup_systemd_services() { + log_info "Setting up systemd services..." + + # Copy service files + cp "$CHATWOOT_APP_PATH/deployment/chatwoot-web.1.service" /etc/systemd/system/ + cp "$CHATWOOT_APP_PATH/deployment/chatwoot-web.target" /etc/systemd/system/ + cp "$CHATWOOT_APP_PATH/deployment/chatwoot-worker.1.service" /etc/systemd/system/ + cp "$CHATWOOT_APP_PATH/deployment/chatwoot-worker.target" /etc/systemd/system/ + + # Update service files for correct user and paths + sed -i "s|User=chatwoot|User=$CHATWOOT_USER|g" /etc/systemd/system/chatwoot-web.1.service + sed -i "s|User=chatwoot|User=$CHATWOOT_USER|g" /etc/systemd/system/chatwoot-worker.1.service + sed -i "s|WorkingDirectory=/home/chatwoot/chatwoot|WorkingDirectory=$CHATWOOT_APP_PATH|g" /etc/systemd/system/chatwoot-web.1.service + sed -i "s|WorkingDirectory=/home/chatwoot/chatwoot|WorkingDirectory=$CHATWOOT_APP_PATH|g" /etc/systemd/system/chatwoot-worker.1.service + + systemctl daemon-reload + systemctl enable chatwoot-web.target + systemctl enable chatwoot-worker.target + + log_success "Systemd services configured" +} + +# Function to start services +start_services() { + log_info "Starting Chatwoot services..." + + systemctl start chatwoot-web.target + systemctl start chatwoot-worker.target + + # Wait for services to start + sleep 5 + + if systemctl is-active --quiet chatwoot-web.target && systemctl is-active --quiet chatwoot-worker.target; then + log_success "Chatwoot services started successfully" + else + log_error "Failed to start Chatwoot services" + log_info "Check logs: journalctl -u chatwoot-web.target -f" + exit 1 + fi +} + +# Function to setup Nginx +setup_nginx() { + log_info "Configuring Nginx as reverse proxy..." + + # Create Nginx configuration + cat > /etc/nginx/sites-available/chatwoot <<'EOF' +server { + listen 80; + server_name _; + + # Point upstream to Chatwoot App Server + set $upstream 127.0.0.1:3000; + + # Nginx strips out underscore in headers by default + # Chatwoot relies on underscore in headers for API + underscores_in_headers on; + + location / { + proxy_pass http://$upstream; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + 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; + proxy_read_timeout 90; + proxy_buffering off; + } +} +EOF + + # Enable site + ln -sf /etc/nginx/sites-available/chatwoot /etc/nginx/sites-enabled/chatwoot + rm -f /etc/nginx/sites-enabled/default + + # Test and reload Nginx + if nginx -t >/dev/null 2>&1; then + systemctl restart nginx + log_success "Nginx configured and restarted" + else + log_error "Nginx configuration error" + nginx -t + exit 1 + fi +} + +# Function to setup SSL with Let's Encrypt +setup_ssl() { + local domain="$1" + local email="$2" + + log_info "Setting up SSL certificate for $domain..." + + certbot certonly --nginx -d "$domain" -m "$email" --agree-tos --non-interactive 2>&1 | tee -a "$LOG_FILE" + + # Update Nginx configuration for HTTPS + cat > /etc/nginx/sites-available/chatwoot </dev/null 2>&1; then + systemctl restart nginx + log_success "SSL certificate installed and Nginx configured" + else + log_error "Nginx configuration error" + exit 1 + fi +} + +# Main installation flow +main() { + log_info "====== Chatwoot Installation Started ======" + + # Detect Ubuntu version + detect_ubuntu_version + + # Check requirements + if ! command_exists curl; then + log_info "Installing curl first..." + apt-get update -qq && apt-get install -y -qq curl + fi + + # Installation steps + update_system + install_dependencies + setup_chatwoot_user + setup_postgresql + setup_redis + setup_ruby + setup_chatwoot + install_gems + compile_assets + setup_systemd_services + start_services + setup_nginx + + # Summary + log_success "====== Chatwoot Installation Complete ======" + echo "" + echo -e "${GREEN}Chatwoot installation completed successfully!${NC}" + echo "" + echo "Access your Chatwoot instance at:" + echo -e "${BLUE} http://$(hostname -I | awk '{print $1}'):3000${NC}" + echo "" + echo "To configure domain and SSL, run:" + echo -e "${BLUE} sudo bash chatwoot_install.sh --ssl --domain yourdomain.com --email your@email.com${NC}" + echo "" + echo "Important next steps:" + echo "1. Update .env file with correct database password" + echo "2. Run database migrations: cd $CHATWOOT_APP_PATH && bundle exec rake db:migrate RAILS_ENV=production" + echo "3. Create admin user and complete initial setup via web interface" + echo "" + echo "For logs, check: journalctl -u chatwoot-web.target -f" + echo "" +} + +# Parse command line arguments +CONFIGURE_SSL=false +DOMAIN="" +EMAIL="" + +while [[ $# -gt 0 ]]; do + case $1 in + --ssl) + CONFIGURE_SSL=true + shift + ;; + --domain) + DOMAIN="$2" + shift 2 + ;; + --email) + EMAIL="$2" + shift 2 + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + +# Run main installation +main + +# Setup SSL if requested +if [ "$CONFIGURE_SSL" = true ]; then + if [ -z "$DOMAIN" ] || [ -z "$EMAIL" ]; then + log_error "Domain and email are required for SSL setup" + exit 1 + fi + setup_ssl "$DOMAIN" "$EMAIL" +fi \ No newline at end of file