Files
apps/ghost/domain.sh
lolwierd ed19997ba0 Implement shared Caddy setup with initializing and unavailable pages for various apps
- Refactor domain scripts for Ghost, Gitea, Jellyfin, Metabase, n8n, NocoDB, Open WebUI, OpenClaw, PicoClaw, Plausible, Signoz, Uptime Kuma, and Vaultwarden to utilize a common Caddy setup script.
- Introduce `caddy-setup.sh` for managing Caddy configurations and handling app initialization states.
- Create `initializing.html` and `unavailable.html` pages to provide user feedback during app deployment and downtime.
- Update domain handling logic to ensure seamless transitions between initializing and operational states.
- Enhance user experience by providing visual indicators for app status during setup and maintenance.
2026-03-28 14:37:33 +05:30

59 lines
1.6 KiB
Bash

#!/bin/bash
APP_NAME="ghost"
APP_DIR="/var/excloud/apps"
APP_UPSTREAM_PORT="${EXC_APP_UPSTREAM_PORT:-2368}"
DOMAIN="${1}"
if [ -z "${DOMAIN}" ]; then
echo "Error: URL argument is required. Example:" >&2
echo "domain.sh sub.example.com" >&2
exit 1
fi
GHOST_DIR="${APP_DIR}/${APP_NAME}"
ENV_FILE="${GHOST_DIR}/.env"
OVERRIDE_FILE="${GHOST_DIR}/compose.override.yml"
ROOT_PASSWORD_FILE="${GHOST_DIR}/.database_root_password"
DATABASE_PASSWORD_FILE="${GHOST_DIR}/.database_password"
if [ ! -f "${ROOT_PASSWORD_FILE}" ]; then
openssl rand -hex 32 > "${ROOT_PASSWORD_FILE}"
fi
if [ ! -f "${DATABASE_PASSWORD_FILE}" ]; then
openssl rand -hex 32 > "${DATABASE_PASSWORD_FILE}"
fi
DATABASE_ROOT_PASSWORD="$(cat "${ROOT_PASSWORD_FILE}")"
DATABASE_PASSWORD="$(cat "${DATABASE_PASSWORD_FILE}")"
# Always rewrite .env with current domain
cat > "${ENV_FILE}" <<EOF
DOMAIN=${DOMAIN}
DATABASE_ROOT_PASSWORD=${DATABASE_ROOT_PASSWORD}
DATABASE_PASSWORD=${DATABASE_PASSWORD}
UPLOAD_LOCATION=./data/ghost
MYSQL_DATA_LOCATION=./data/mysql
EOF
cat > "${OVERRIDE_FILE}" <<EOF
services:
ghost:
ports:
- "127.0.0.1:${APP_UPSTREAM_PORT}:2368"
EOF
source /var/excloud/scripts/caddy-setup.sh
if is_app_ready "$GHOST_DIR"; then
# Restart to pick up new domain from .env
docker compose -f "${GHOST_DIR}/compose.yml" -f "${OVERRIDE_FILE}" up -d db ghost
switch_domain "$DOMAIN" "$APP_UPSTREAM_PORT" "$GHOST_DIR"
else
setup_initializing_page "$DOMAIN" "$APP_NAME" "$GHOST_DIR"
docker compose -f "${GHOST_DIR}/compose.yml" -f "${OVERRIDE_FILE}" up -d db ghost
wait_and_switch_to_proxy "$DOMAIN" "$APP_UPSTREAM_PORT" "$GHOST_DIR" &
fi