-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
74 lines (65 loc) · 2.8 KB
/
Copy pathentrypoint.sh
File metadata and controls
74 lines (65 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Wrapper around the upstream /usr/bin/start-container.orig.
# Starts dbus and avahi-daemon, then hands off to the original entrypoint.
#
# we used to be very forgiving here ("|| true" everywhere) which masked
# real config problems. tighten that up: bail on the things that LMS
# can't recover from (dbus down means avahi cant register, avahi down
# means ShairTunes / RaopBridge / CastBridge / UPnPBridge fail silently).
# best effort still applies for the cleanup of stale state.
set -u
set -o pipefail
log() { printf '[entrypoint] %s\n' "$*"; }
warn() { printf '[entrypoint] WARN: %s\n' "$*" >&2; }
die() { printf '[entrypoint] FATAL: %s\n' "$*" >&2; exit 1; }
# dbus needs /run/dbus and a machine-id. /var/lib/dbus exists in the
# upstream image, only the runtime dir and a fresh daemon are needed.
mkdir -p /run/dbus /var/run/dbus
if [ ! -s /var/lib/dbus/machine-id ]; then
dbus-uuidgen > /var/lib/dbus/machine-id \
|| die "could not write /var/lib/dbus/machine-id"
fi
# wipe stale pid if a volume cached it from a previous container run
rm -f /run/dbus/pid
# fork dbus. without --print-address we cant tell from exit code alone
# whether it actually came up. check for the pid file after.
if ! dbus-daemon --system --fork --nopidfile --print-address 2>/dev/null; then
dbus-daemon --system --fork || die "dbus-daemon failed to start"
fi
# wait up to 5s for dbus socket to appear. without it avahi-daemon
# exits immediately with "WARNING: Failed to contact D-Bus daemon".
for _ in 1 2 3 4 5; do
[ -S /run/dbus/system_bus_socket ] && break
sleep 1
done
[ -S /run/dbus/system_bus_socket ] || die "dbus socket never appeared"
log "dbus is up"
# avahi wants its own runtime dir, also wipes stale state.
mkdir -p /var/run/avahi-daemon
chown avahi:avahi /var/run/avahi-daemon 2>/dev/null \
|| warn "could not chown /var/run/avahi-daemon (image without avahi user?)"
rm -f /var/run/avahi-daemon/pid
# rlimits inside containers behave oddly, --no-rlimits avoids spurious
# EPERM during startup. -D detaches.
if ! avahi-daemon -D --no-rlimits; then
die "avahi-daemon failed to start"
fi
# wait for avahi to register on the system bus instead of guessing with
# a fixed sleep. dbus-send fails fast if the name isnt there yet.
avahi_ready=0
for _ in 1 2 3 4 5 6 7 8 9 10; do
if dbus-send --system --print-reply --dest=org.freedesktop.Avahi \
/ org.freedesktop.Avahi.Server.GetVersionString >/dev/null 2>&1; then
avahi_ready=1
break
fi
sleep 0.5
done
if [ "$avahi_ready" = 1 ]; then
log "avahi is up"
else
# not fatal: LMS itself still runs, only the mDNS-using plugins are
# affected. better to log loudly than to refuse to start lyrion.
warn "avahi did not respond on the system bus within 5s, mDNS plugins may misbehave"
fi
exec /usr/bin/start-container.orig "$@"