plex-test/start_pms

40 lines
1.4 KiB
Bash

#!/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"
if [ ! -d "$PLEX_MEDIA_SERVER_CONFIG_DIR" ]
then
mkdir -p "$PLEX_MEDIA_SERVER_CONFIG_DIR" && \
chown $UID:$GID "$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 $UID:$GID [ ! -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
export LD_LIBRARY_PATH="${PLEX_MEDIA_SERVER_HOME}:$LD_LIBRARY_PATH"
export TMPDIR="${PLEX_MEDIA_SERVER_TMPDIR}"
# Allow Plex group to write to tmpdir
chgrp $GID "$TMPDIR"
chmod g+rwx "$TMPDIR"
PIDFILE="${PLEX_MEDIA_SERVER_CONFIG_DIR}/plexmediaserver.pid"
if [ -f "$PIDFILE" ]; then
rm -f "$PIDFILE"
fi
exec su-exec $UID:$GID "$PLEX_MEDIA_SERVER_HOME/Plex Media Server"