81a27f3e9b
Build and Push Docker Container / build-and-push (push) Successful in 4m53s
- Remove stale X lock and socket files before starting Xvfb. - Prevent false active-display errors after container restarts. - Keep Obsidian able to create the CLI socket for API commands.
66 lines
2.3 KiB
Bash
66 lines
2.3 KiB
Bash
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
mkdir -p "$XDG_RUNTIME_DIR" /root/.config /root/.config/obsidian /root/.cache /root/.local/share /run/dbus
|
|
chmod 700 "$XDG_RUNTIME_DIR"
|
|
|
|
# Electron apps are happier with a DBus session, even under Xvfb.
|
|
if command -v dbus-launch >/dev/null 2>&1; then
|
|
eval "$(dbus-launch --sh-syntax)"
|
|
export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
|
|
fi
|
|
|
|
# Enable the official Obsidian CLI and register mounted vaults in global desktop-app settings.
|
|
# This is the same CLI setting toggled by Settings > General > Advanced > Command line interface.
|
|
DEFAULT_VAULT_PATH="$(python /app/scripts/render_config.py | tail -n 1)"
|
|
|
|
# Start a virtual X server for the official Obsidian desktop app.
|
|
# Some container/image restarts can leave stale X lock/socket files behind. In
|
|
# this dedicated container nothing else should own DISPLAY, so clear them before
|
|
# starting Xvfb to avoid "Server is already active for display" false positives.
|
|
DISPLAY_NUMBER="${DISPLAY#:}"
|
|
rm -f "/tmp/.X${DISPLAY_NUMBER}-lock" "/tmp/.X11-unix/X${DISPLAY_NUMBER}"
|
|
|
|
Xvfb "$DISPLAY" -screen 0 "${XVFB_SCREEN:-1280x1024x24}" -nolisten tcp >/tmp/xvfb.log 2>&1 &
|
|
XVFB_PID=$!
|
|
|
|
cleanup() {
|
|
if [ -n "${OBSIDIAN_PID:-}" ] && kill -0 "$OBSIDIAN_PID" 2>/dev/null; then
|
|
kill "$OBSIDIAN_PID" 2>/dev/null || true
|
|
fi
|
|
kill "$XVFB_PID" 2>/dev/null || true
|
|
}
|
|
trap cleanup INT TERM EXIT
|
|
|
|
# Open the mounted vault using the official desktop app. The official CLI talks
|
|
# to this running app through $XDG_RUNTIME_DIR/.obsidian-cli.sock.
|
|
/opt/Obsidian/obsidian \
|
|
--no-sandbox \
|
|
--disable-gpu \
|
|
--disable-software-rasterizer \
|
|
--disable-dev-shm-usage \
|
|
--disable-features=UseOzonePlatform \
|
|
"${DEFAULT_VAULT_PATH}" \
|
|
>/tmp/obsidian.log 2>&1 &
|
|
OBSIDIAN_PID=$!
|
|
|
|
SOCKET="$XDG_RUNTIME_DIR/.obsidian-cli.sock"
|
|
WAIT_SECONDS="${OBSIDIAN_STARTUP_TIMEOUT:-60}"
|
|
STARTED=0
|
|
while [ "$STARTED" -lt "$WAIT_SECONDS" ]; do
|
|
if [ -S "$SOCKET" ]; then
|
|
break
|
|
fi
|
|
STARTED=$((STARTED + 1))
|
|
sleep 1
|
|
done
|
|
|
|
if [ ! -S "$SOCKET" ]; then
|
|
echo "WARNING: Official Obsidian CLI socket was not created at $SOCKET after ${WAIT_SECONDS}s." >&2
|
|
echo "The HTTP API will still start, but /commands may fail until Obsidian exposes the CLI socket." >&2
|
|
echo "Obsidian log tail:" >&2
|
|
tail -80 /tmp/obsidian.log >&2 || true
|
|
fi
|
|
|
|
exec uv run python -m app.main
|