55 lines
2.2 KiB
Bash
55 lines
2.2 KiB
Bash
#!/usr/bin/env bash
|
|
# Mopidy entrypoint — runs as root, fixes permissions, then drops to mopidy user.
|
|
set -e
|
|
|
|
# Fix ownership of the data volume (may be stale from a previous container build
|
|
# with a different mopidy uid, or from Docker initialising a new volume as root).
|
|
chown -R mopidy:audio /var/lib/mopidy 2>/dev/null || true
|
|
|
|
FIFO=/audio/mopidy.fifo
|
|
|
|
# Create FIFO if missing (init-pipes.sh should have done this, but be safe)
|
|
if [[ ! -p "$FIFO" ]]; then
|
|
echo "[mopidy] Creating FIFO: $FIFO"
|
|
mkfifo "$FIFO"
|
|
chmod 666 "$FIFO"
|
|
fi
|
|
|
|
echo "[mopidy] FIFO ready: $FIFO"
|
|
|
|
STREAM_FIFO=/audio/stream.fifo
|
|
|
|
if [[ ! -p "$STREAM_FIFO" ]]; then
|
|
echo "[mopidy] Creating FIFO: $STREAM_FIFO"
|
|
mkfifo "$STREAM_FIFO"
|
|
chmod 666 "$STREAM_FIFO"
|
|
fi
|
|
|
|
# Hold stream.fifo open O_RDWR in a background process.
|
|
# GStreamer's filesink opens the FIFO write-only, which blocks until a reader
|
|
# exists. This holder acts as that persistent reader so the pipeline can start
|
|
# regardless of whether stream-relay is up. leaky=1 on the GStreamer queue
|
|
# ensures Mopidy never blocks even if the relay is slow.
|
|
(while true; do exec 6<>"$STREAM_FIFO"; sleep 86400; done) &
|
|
|
|
echo "[mopidy] stream.fifo ready: $STREAM_FIFO"
|
|
|
|
# Load Spotify credentials from shared config volume (written by the settings UI).
|
|
# Values here take precedence over env vars from docker-compose / .env.
|
|
_SPOTIFY_JSON=/config/shared/spotify.json
|
|
if [[ -f "$_SPOTIFY_JSON" ]]; then
|
|
_ID=$(python3 -c "import json; d=json.load(open('$_SPOTIFY_JSON')); print(d.get('client_id',''))" 2>/dev/null || true)
|
|
_SEC=$(python3 -c "import json; d=json.load(open('$_SPOTIFY_JSON')); print(d.get('client_secret',''))" 2>/dev/null || true)
|
|
[[ -n "$_ID" ]] && export SPOTIFY_CLIENT_ID="$_ID"
|
|
[[ -n "$_SEC" ]] && export SPOTIFY_CLIENT_SECRET="$_SEC"
|
|
echo "[mopidy] Spotify credentials loaded from shared config"
|
|
fi
|
|
|
|
# Expand only our own vars — leave Mopidy's $XDG_* vars untouched
|
|
envsubst '${SPOTIFY_CLIENT_ID}${SPOTIFY_CLIENT_SECRET}${SNAPSERVER_HOST}${BEETS_HOST}' \
|
|
< /config/mopidy.conf > /tmp/mopidy.conf
|
|
echo "[mopidy] Config expanded from template"
|
|
|
|
# Drop from root → mopidy user for the actual Mopidy process
|
|
exec gosu mopidy "$@"
|