mirror of
https://github.com/spritsail/plex-media-server.git
synced 2024-12-20 11:34:36 +00:00
Add new entrypoint/config script
This commit is contained in:
parent
93aeb86ab0
commit
f4602958fd
23
Dockerfile
23
Dockerfile
@ -147,8 +147,9 @@ RUN find -exec sh -c 'file "{}" | grep -q ELF && strip --strip-debug "{}"' \; \
|
|||||||
&& mv usr/bin/curl /output/usr/bin \
|
&& mv usr/bin/curl /output/usr/bin \
|
||||||
&& mv usr/bin/xml /output/usr/bin/xmlstarlet
|
&& mv usr/bin/xml /output/usr/bin/xmlstarlet
|
||||||
|
|
||||||
ADD start_pms /output/usr/sbin/start_pms
|
ADD entrypoint /output/usr/local/bin/
|
||||||
RUN chmod +x /output/usr/sbin/start_pms
|
ADD *.sh /output/usr/local/bin/
|
||||||
|
RUN chmod +x /output/usr/local/bin/*
|
||||||
|
|
||||||
#=========================
|
#=========================
|
||||||
|
|
||||||
@ -172,16 +173,26 @@ LABEL maintainer="Spritsail <plex@spritsail.io>" \
|
|||||||
io.spritsail.version.libstdcpp=${LIBSTDCPP_VER} \
|
io.spritsail.version.libstdcpp=${LIBSTDCPP_VER} \
|
||||||
io.spritsail.version.xmlstarlet=${XMLSTAR_VER}
|
io.spritsail.version.xmlstarlet=${XMLSTAR_VER}
|
||||||
|
|
||||||
ENV SUID=900 SGID=900
|
WORKDIR /usr/lib/plexmediaserver
|
||||||
|
|
||||||
COPY --from=builder /output/ /
|
COPY --from=builder /output/ /
|
||||||
|
|
||||||
|
ENV SUID=900 SGID=900 \
|
||||||
|
PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS="6" \
|
||||||
|
PLEX_MEDIA_SERVER_MAX_STACK_SIZE="3000" \
|
||||||
|
PLEX_MEDIA_SERVER_TMPDIR="/tmp" \
|
||||||
|
PLEX_MEDIA_SERVER_HOME="/usr/lib/plexmediaserver" \
|
||||||
|
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/var/lib/plexmediaserver"
|
||||||
|
|
||||||
HEALTHCHECK --interval=10s --timeout=5s \
|
HEALTHCHECK --interval=10s --timeout=5s \
|
||||||
CMD [ "wget", "-O", "/dev/null", "-T", "10", "-q", "localhost:32400/identity" ]
|
CMD [ "wget", "-O", "/dev/null", "-T", "10", "-q", "localhost:32400/identity" ]
|
||||||
|
|
||||||
WORKDIR /usr/lib/plexmediaserver
|
|
||||||
|
|
||||||
EXPOSE 32400
|
EXPOSE 32400
|
||||||
|
|
||||||
|
VOLUME ["/config", "/transcode"]
|
||||||
|
|
||||||
|
RUN mkdir -p "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR" \
|
||||||
|
&& ln -sfv /config "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR/Plex Media Server"
|
||||||
|
|
||||||
ENTRYPOINT ["/sbin/tini", "--"]
|
ENTRYPOINT ["/sbin/tini", "--"]
|
||||||
CMD ["/usr/sbin/start_pms"]
|
CMD ["/usr/local/bin/entrypoint"]
|
||||||
|
28
entrypoint
Executable file
28
entrypoint
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if su-exec -e [ ! -w "/config" ]; then
|
||||||
|
2>&1 echo "Warning: No permission to write in '/config' directory."
|
||||||
|
2>&1 echo " Correcting permissions to prevent a crash"
|
||||||
|
2>&1 echo
|
||||||
|
(
|
||||||
|
set -x
|
||||||
|
chown $SUID:$SGID /config
|
||||||
|
chmod o+rw /config
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec su-exec -e sh <<EOF
|
||||||
|
# Generate a default configuration, including some user-specified values
|
||||||
|
if [ ! -e "/config/Preferences.xml" ]; then
|
||||||
|
gen-config.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Duplicate the Plex logs to stdout (docker logs)
|
||||||
|
tail -Fn 0 "/config/Logs/Plex Media Server.log" 2>/dev/null &
|
||||||
|
|
||||||
|
# Use a random pidfile
|
||||||
|
export PLEX_MEDIA_SERVER_PIDFILE="\$(mktemp -ut pms-pid.XXXXXX)"
|
||||||
|
|
||||||
|
exec "\$PLEX_MEDIA_SERVER_HOME/Plex Media Server"
|
||||||
|
EOF
|
64
gen-config.sh
Executable file
64
gen-config.sh
Executable file
@ -0,0 +1,64 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
PREF_FILE="${1:-/config/Preferences.xml}"
|
||||||
|
|
||||||
|
getPref() {
|
||||||
|
xmlstarlet sel -T -t -m "/Preferences" -v "@$1" -n "${PREF_FILE}"
|
||||||
|
}
|
||||||
|
setPref() {
|
||||||
|
count="$(xmlstarlet sel -t -v "count(/Preferences/@$1)" "${PREF_FILE}")"
|
||||||
|
if [ $(($count + 0)) -gt 0 ]; then
|
||||||
|
xmlstarlet ed --inplace --update "/Preferences/@$1" -v "$2" "${PREF_FILE}" 2>/dev/null
|
||||||
|
else
|
||||||
|
xmlstarlet ed --inplace --insert "/Preferences" --type attr -n "$1" -v "$2" "${PREF_FILE}" 2>/dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a default config file allowing external access
|
||||||
|
echo -e $'<?xml version="1.0" encoding="utf-8"?>\n<Preferences />' > "/config/Preferences.xml"
|
||||||
|
|
||||||
|
# Enforced defaults. These can be changed manually afterwards.
|
||||||
|
setPref "AcceptedEULA" "1"
|
||||||
|
setPref "TranscoderTempDirectory" "/transcode"
|
||||||
|
|
||||||
|
# The following below is ripped directly from the official (inferior) Plex container:
|
||||||
|
# https://github.com/plexinc/pms-docker/blob/155f00c71b50f94c73ffea0aae16cc61ef957df7/root/etc/cont-init.d/40-plex-first-run
|
||||||
|
|
||||||
|
# Setup Server's client identifier
|
||||||
|
serial="$(getPref "MachineIdentifier")"
|
||||||
|
if [ -z "${serial}" ]; then
|
||||||
|
serial="$(cat /proc/sys/kernel/random/uuid)"
|
||||||
|
setPref "MachineIdentifier" "${serial}"
|
||||||
|
fi
|
||||||
|
clientId="$(getPref "ProcessedMachineIdentifier")"
|
||||||
|
if [ -z "${clientId}" ]; then
|
||||||
|
clientId="$(echo -n "${serial}- Plex Media Server" | sha1sum | cut -b 1-40)"
|
||||||
|
setPref "ProcessedMachineIdentifier" "${clientId}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get server token and only turn claim token into server token if we have former but not latter.
|
||||||
|
token="$(getPref "PlexOnlineToken")"
|
||||||
|
if [ ! -z "${PLEX_CLAIM}" ] && [ -z "${token}" ]; then
|
||||||
|
echo "Attempting to obtain server token from claim token"
|
||||||
|
loginInfo="$(curl -X POST \
|
||||||
|
-H 'X-Plex-Client-Identifier: '${clientId} \
|
||||||
|
-H 'X-Plex-Product: Plex Media Server'\
|
||||||
|
-H 'X-Plex-Version: 1.1' \
|
||||||
|
-H 'X-Plex-Provides: server' \
|
||||||
|
-H 'X-Plex-Platform: Linux' \
|
||||||
|
-H 'X-Plex-Platform-Version: 1.0' \
|
||||||
|
-H 'X-Plex-Device-Name: PlexMediaServer' \
|
||||||
|
-H 'X-Plex-Device: Linux' \
|
||||||
|
"https://plex.tv/api/claim/exchange?token=${PLEX_CLAIM}")"
|
||||||
|
token="$(echo "$loginInfo" | sed -n 's/.*<authentication-token>\(.*\)<\/authentication-token>.*/\1/p')"
|
||||||
|
|
||||||
|
if [ "$token" ]; then
|
||||||
|
echo "Token obtained successfully"
|
||||||
|
setPref "PlexOnlineToken" "${token}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
test -n "${ADVERTISE_IP}" && setPref "customConnections" "${ADVERTISE_IP}"
|
||||||
|
test -n "${ALLOWED_NETWORKS}" && setPref "allowedNetworks" "${ALLOWED_NETWORKS}"
|
||||||
|
test -n "${DISABLE_REMOTE_SEC}" && setPref "disableRemoteSecurity" "1"
|
43
start_pms
43
start_pms
@ -1,43 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Default values
|
|
||||||
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS="${PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS:-6}"
|
|
||||||
export PLEX_MEDIA_SERVER_HOME="${PLEX_MEDIA_SERVER_HOME:-/usr/lib/plexmediaserver}"
|
|
||||||
export PLEX_MEDIA_SERVER_MAX_STACK_SIZE="${PLEX_MEDIA_SERVER_MAX_STACK_SIZE:-3000}"
|
|
||||||
export PLEX_MEDIA_SERVER_TMPDIR="${PLEX_MEDIA_SERVER_TMPDIR:-/tmp}"
|
|
||||||
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR:-/config}"
|
|
||||||
export PLEX_MEDIA_SERVER_CONFIG_DIR="${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}/Plex Media Server"
|
|
||||||
export TMPDIR="${PLEX_MEDIA_SERVER_TMPDIR}"
|
|
||||||
|
|
||||||
if [ ! -d "$PLEX_MEDIA_SERVER_CONFIG_DIR" ]; then
|
|
||||||
mkdir -p "$PLEX_MEDIA_SERVER_CONFIG_DIR" && \
|
|
||||||
chown $SUID:$SGID "$PLEX_MEDIA_SERVER_CONFIG_DIR"
|
|
||||||
if [ ! $? -eq 0 ]; then
|
|
||||||
echo "WARNING COULDN'T CREATE $PLEX_MEDIA_SERVER_CONFIG_DIR, MAKE SURE I HAVE PERMISSON TO DO THAT!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if su-exec -e [ ! -w "$PLEX_MEDIA_SERVER_CONFIG_DIR" ]; then
|
|
||||||
echo "ERROR: CANNOT WRITE IN $PLEX_MEDIA_SERVER_CONFIG_DIR, MAKE SURE I HAVE PERMISSION TO DO THAT!"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -e "$PLEX_MEDIA_SERVER_CONFIG_DIR/Preferences.xml" ]; then
|
|
||||||
# Create a default config file allowing external access
|
|
||||||
echo -e '<?xml version="1.0" encoding="utf-8"?>\n<Preferences disableRemoteSecurity="1" />' \
|
|
||||||
>> "$PLEX_MEDIA_SERVER_CONFIG_DIR/Preferences.xml"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Allow Plex group to write to tmpdir
|
|
||||||
chgrp $SGID "$TMPDIR"
|
|
||||||
chmod g+rwx "$TMPDIR"
|
|
||||||
|
|
||||||
PIDFILE="${PLEX_MEDIA_SERVER_CONFIG_DIR}/plexmediaserver.pid"
|
|
||||||
if [ -f "$PIDFILE" ]; then
|
|
||||||
rm -f "$PIDFILE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
tail -F "$PLEX_MEDIA_SERVER_CONFIG_DIR/Logs/Plex Media Server.log" >/proc/1/fd/1 2>/dev/null &
|
|
||||||
|
|
||||||
exec su-exec -e "$PLEX_MEDIA_SERVER_HOME/Plex Media Server"
|
|
Loading…
Reference in New Issue
Block a user