114 lines
3.6 KiB
Bash
Executable File
114 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
## Discourse Installation Script for Netcup RS 8000
|
|
## Run this ON the Netcup server: ssh netcup "bash -s" < scripts/install.sh
|
|
## Or: ssh netcup, then cd /opt/discourse && bash scripts/install.sh
|
|
|
|
DISCOURSE_DIR="/opt/discourse"
|
|
REPO_URL="https://github.com/discourse/discourse_docker.git"
|
|
|
|
echo "=== Discourse Installation for cadCAD Community Forum ==="
|
|
echo ""
|
|
|
|
# 1. Check for swap (Discourse needs it for 2GB RAM limit)
|
|
echo "[1/6] Checking swap space..."
|
|
SWAP_TOTAL=$(free -m | awk '/^Swap:/ {print $2}')
|
|
if [ "$SWAP_TOTAL" -lt 2000 ]; then
|
|
echo " WARNING: Less than 2GB swap detected (${SWAP_TOTAL}MB)."
|
|
echo " Creating 2GB swap file..."
|
|
if [ ! -f /swapfile ]; then
|
|
fallocate -l 2G /swapfile
|
|
chmod 600 /swapfile
|
|
mkswap /swapfile
|
|
swapon /swapfile
|
|
echo '/swapfile none swap sw 0 0' >> /etc/fstab
|
|
echo " Swap file created and enabled."
|
|
else
|
|
echo " /swapfile already exists. Enabling if not active..."
|
|
swapon /swapfile 2>/dev/null || true
|
|
fi
|
|
else
|
|
echo " Swap OK: ${SWAP_TOTAL}MB"
|
|
fi
|
|
|
|
# 2. Clone discourse_docker
|
|
echo ""
|
|
echo "[2/6] Setting up Discourse Docker..."
|
|
if [ -d "$DISCOURSE_DIR/.git" ]; then
|
|
echo " discourse_docker already cloned at $DISCOURSE_DIR"
|
|
cd "$DISCOURSE_DIR"
|
|
git pull
|
|
else
|
|
echo " Cloning discourse_docker..."
|
|
git clone "$REPO_URL" "$DISCOURSE_DIR"
|
|
cd "$DISCOURSE_DIR"
|
|
fi
|
|
|
|
# 3. Copy app.yml config
|
|
echo ""
|
|
echo "[3/6] Installing app.yml configuration..."
|
|
if [ -f "containers/app.yml" ]; then
|
|
echo " Backing up existing app.yml to containers/app.yml.backup"
|
|
cp containers/app.yml "containers/app.yml.backup.$(date +%Y%m%d%H%M%S)"
|
|
fi
|
|
|
|
# The app.yml should already be in the repo root from our config
|
|
if [ -f "app.yml" ]; then
|
|
cp app.yml containers/app.yml
|
|
echo " app.yml copied to containers/"
|
|
else
|
|
echo " ERROR: app.yml not found in repo root."
|
|
echo " Please copy it manually: cp /path/to/app.yml containers/app.yml"
|
|
exit 1
|
|
fi
|
|
|
|
# 4. Ensure traefik-public network exists
|
|
echo ""
|
|
echo "[4/6] Checking Docker networks..."
|
|
if docker network inspect traefik-public >/dev/null 2>&1; then
|
|
echo " traefik-public network exists."
|
|
else
|
|
echo " Creating traefik-public network..."
|
|
docker network create traefik-public
|
|
fi
|
|
|
|
# 5. Bootstrap Discourse (this takes 5-10 minutes)
|
|
echo ""
|
|
echo "[5/6] Bootstrapping Discourse container..."
|
|
echo " This will take 5-10 minutes. Building image and precompiling assets..."
|
|
echo ""
|
|
./launcher bootstrap app
|
|
|
|
# 6. Start and connect to Traefik network
|
|
echo ""
|
|
echo "[6/6] Starting Discourse and connecting to Traefik..."
|
|
./launcher start app
|
|
|
|
# Connect to traefik-public network
|
|
CONTAINER_ID=$(docker ps -q -f name=app)
|
|
if [ -n "$CONTAINER_ID" ]; then
|
|
docker network connect traefik-public "$CONTAINER_ID" 2>/dev/null || echo " Already connected to traefik-public"
|
|
echo " Container connected to traefik-public network."
|
|
else
|
|
echo " WARNING: Could not find running discourse container."
|
|
fi
|
|
|
|
echo ""
|
|
echo "=== Discourse Installation Complete ==="
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Add cadcad-forum.jeffemmett.com to Cloudflare tunnel"
|
|
echo " 2. Create admin account:"
|
|
echo " cd /opt/discourse && ./launcher enter app"
|
|
echo " rake admin:create"
|
|
echo " 3. Configure SMTP in containers/app.yml when ready"
|
|
echo " 4. Visit https://cadcad-forum.jeffemmett.com"
|
|
echo ""
|
|
echo "Useful commands:"
|
|
echo " ./launcher logs app # View logs"
|
|
echo " ./launcher restart app # Restart"
|
|
echo " ./launcher rebuild app # Rebuild after config changes"
|
|
echo " ./launcher enter app # Shell into container"
|
|
echo " ./launcher stop app # Stop"
|