Initial Commit

This commit is contained in:
Adam Dodman 2016-08-26 22:26:39 +01:00
commit 3ebf1a0777
2 changed files with 109 additions and 0 deletions

62
Dockerfile Normal file
View File

@ -0,0 +1,62 @@
FROM alpine:3.4
MAINTAINER Adam Dodman <adam.dodman@gmx.com>
ENV UID=787 UNAME=plex GID=990 GNAME=media
ENV debs "libc6 libgcc1 libstdc++6 plexmediaserver"
ENV destdir "/plex"
ADD start_pms.patch /tmp/start_pms.patch
WORKDIR /tmp
RUN addgroup -g $GID $GNAME \
&& adduser -SH -u $UID -G $GNAME -s /usr/sbin/nologin $UNAME \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& apk add --no-cache xz binutils patchelf openssl file \
&& wget http://ftp.debian.org/debian/pool/main/g/glibc/libc6_2.23-5_amd64.deb \
&& wget http://ftp.debian.org/debian/pool/main/g/gcc-4.9/libgcc1_4.9.2-10_amd64.deb \
&& wget http://ftp.debian.org/debian/pool/main/g/gcc-4.9/libstdc++6_4.9.2-10_amd64.deb \
&& wget -O plexmediaserver.deb 'https://plex.tv/downloads/latest/1?channel=8&build=linux-ubuntu-x86_64&distro=ubuntu' \
&& for pkg in $debs; do \
mkdir $pkg; \
cd $pkg; \
ar x ../$pkg*.deb; \
tar -xf data.tar.*; \
cd ..; \
done \
&& mkdir -p $destdir/lib \
&& mv libc6/lib/x86_64-linux-gnu/* $destdir/lib \
&& mv libgcc1/lib/x86_64-linux-gnu/* $destdir/lib \
&& mv libstdc++6/usr/lib/x86_64-linux-gnu/* $destdir/lib \
&& echo "export GLIBC_LIBRARY_PATH=/plex/lib" >"$destdir/lib/vars.sh" \
&& echo "export GLIBC_LD_LINUX_SO=/plex/lib/ld-linux-x86-64.so.2" >>"$destdir/lib/vars.sh" \
&& chmod +x $destdir/lib/vars.sh \
&& . $destdir/lib/vars.sh \
&& find plexmediaserver/usr/lib/plexmediaserver -type f -perm /0111 -exec sh -c "file --brief \"{}\" | grep -q "ELF" && patchelf --set-interpreter \"$GLIBC_LD_LINUX_SO\" \"{}\" " \; \
&& mv /tmp/start_pms.patch plexmediaserver/usr/sbin/ \
&& cd plexmediaserver/usr/sbin/ \
&& patch < start_pms.patch \
&& cd /tmp \
&& sed -i "s|<destdir>|$destdir|" plexmediaserver/usr/sbin/start_pms \
&& mv plexmediaserver/usr/sbin/start_pms $destdir/ \
&& mv plexmediaserver/usr/lib/plexmediaserver $destdir/plex-media-server \
&& apk del --no-cache xz binutils patchelf file \
&& rm -rf /tmp/*
USER plex
WORKDIR ["/plex"]
CMD ["/plex/start_pms"]

47
start_pms.patch Normal file
View File

@ -0,0 +1,47 @@
--- plexmediaserver/usr/sbin/start_pms
+++ start_pms
@@ -1,13 +1,11 @@
#!/bin/sh
-#change these parameters in /etc/default/plexmediaserver
-export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
-export PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
-export PLEX_MEDIA_SERVER_MAX_STACK_SIZE=3000
-export PLEX_MEDIA_SERVER_TMPDIR=/tmp
-export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${HOME}/Library/Application Support"
-
-test -f /etc/default/plexmediaserver && . /etc/default/plexmediaserver
+# 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:-<destdir>/plex-media-server}"
+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/plex}"
if [ ! -d "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR" ]
then
@@ -19,14 +17,18 @@ then
fi
fi
-export LD_LIBRARY_PATH="${PLEX_MEDIA_SERVER_HOME}"
+. <destdir>/lib/vars.sh
+export LD_LIBRARY_PATH="${PLEX_MEDIA_SERVER_HOME}:${GLIBC_LIBRARY_PATH}"
export TMPDIR="${PLEX_MEDIA_SERVER_TMPDIR}"
-echo $PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS $PLEX_MEDIA_SERVER_MAX_STACK_SIZE $PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR
+# Fix Locale, busybox doesn't care about it
+export LANG=C
+export LC_ALL=C
-ulimit -s $PLEX_MAX_STACK_SIZE
+cd "$PLEX_MEDIA_SERVER_HOME"
-# Add sleep - Possible fix for start on boot.
-sleep 3
+if [ -f /config/plex/Plex\ Media\ Server/plexmediaserver.pid ]; then
+ rm -f /config/plex/Plex\ Media\ Server/plexmediaserver.pid
+fi
-(cd /usr/lib/plexmediaserver; ./Plex\ Media\ Server)
+exec "$PLEX_MEDIA_SERVER_HOME/Plex Media Server"