wiki_ghostguild/scripts/export-content-cron.sh
Jennie Robinson Faber 15a5c49324 Add bind-mount liveness guard to cron container
DokPloy rm-rf's the host code dir on every redeploy, orphaning the
long-running cron container's ./content and ./.git bind mounts (pinned to
the now-deleted inode). The wiki export then spins forever in fs.mkdir
against the dead directory and never commits.

mount-guard.sh detects a stale mount (directory hard-link count < 2 = a
deleted inode) and re-binds it via docker restart, run every 15 min from
cron and once at the top of export-content-cron.sh as a fast-fail.
2026-05-24 15:28:47 +01:00

45 lines
1.5 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
# Daily wiki content export — run via cron:
# 0 4 * * * /path/to/wiki-ghostguild/scripts/export-content-cron.sh >> /var/log/wiki-export.log 2>&1
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$REPO_DIR"
# Bail out (and self-heal) if a DokPloy redeploy left our bind mounts pinned to
# a deleted inode — otherwise the fs.mkdir in export-content.js spins forever.
# mount-guard.sh restarts the container to re-bind; this run is then aborted and
# the next scheduled export runs against fresh mounts.
"$(dirname "$0")/mount-guard.sh"
# Source env vars from outline.env if it exists (for host-based cron),
# otherwise rely on env vars from docker-compose env_file
if [[ -f outline.env ]]; then
while IFS='=' read -r key value; do
[[ -z "$key" || "$key" =~ ^# ]] && continue
export "$key=$value"
done < outline.env
fi
# Map Outline's URL to OUTLINE_URL if not already set
export OUTLINE_URL="${OUTLINE_URL:-${URL:-}}"
# Support both OUTLINE_API_KEY (outline.env) and OUTLINE_API_TOKEN (scripts)
export OUTLINE_API_TOKEN="${OUTLINE_API_TOKEN:-${OUTLINE_API_KEY:-}}"
if [[ -z "${OUTLINE_API_TOKEN:-}" ]]; then
echo "Error: OUTLINE_API_TOKEN or OUTLINE_API_KEY must be set" >&2
exit 1
fi
# Run export
node scripts/export-content.js
# Commit and push if there are changes. -A stages deletions and renames too,
# so docs removed or renamed in Outline actually propagate to git.
git add -A content/wiki/
if ! git diff --cached --quiet; then
git commit -m "wiki content export $(date +%Y-%m-%d)"
git push
fi