Plex via FFP , managed to get running - Question for Mijzelf

Oxnas 810 based
barmalej2
Posts: 2387
Joined: Sun Apr 29, 2012 5:24 pm

Re: Plex via FFP , managed to get running - Question for Mij

Post by barmalej2 » Thu Jan 24, 2013 9:58 am

/ffp/start/plexmediaserver.sh

Code: Select all

#!/ffp/bin/sh

# PROVIDE: Plex Media Server
# REQUIRE: 
# BEFORE:

. /ffp/etc/ffp.subr

name="plexmediaserver"
start_cmd="start_plex"
stop_cmd="stop_plex"
restart_cmd="restart_plex"
status_cmd="plex_status"

PMS_RUN_USER="plex"
PLEXUID=5000
PID_FILE=/ffp/plex/Plex\ Media\ Server/plexmediaserver.pid
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/ffp/plex


start_plex ()
{
    test -f "/ffp/sbin/start_pms" || exit 0

#Create a user to run Plex Media Server

    if ! cat /ffp/etc/passwd | grep ^plex:
    then echo "${PMS_RUN_USER}:x:${PLEXUID}:${PLEXUID}:PLEX Media Server:${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}:/ffp/bin/false" >>/ffp/etc/passwd
    fi

    if [ -f "$PID_FILE" ]
    then echo "Plex Media server is already running..."
         ps aux | grep plex
    exit 0
    else echo -n "Starting Plex Media Server: "
         su $PMS_RUN_USER -s /ffp/bin/sh -c "/ffp/sbin/start_pms &" && echo "done" || echo "Something is wrong and Plex Media Server can't start"
    fi
}

stop_plex ()
{
    if [ ! -f "$PID_FILE" ]
    then echo "It seems that Plex Media Server is not running (no process found)..."
    exit 0
    else echo -n "Stopping Plex Media Server..."
         kill -15 `cat "$PID_FILE"` && echo "done" || echo "Something is wrong and Plex Media Server can't be stopped"
    fi
}

restart_plex ()
{
    #to be filled
	#sh $0 stop
    #sh $0 start
}

plex_status ()
{
    if [ -f "$PID_FILE" ]
    then echo "Plex Media Server is running..."
         ps aux | grep plex
    else echo "Plex Media Server is not running"
    fi
}

run_rc_command "$1"
/ffp/sbin/start_pms

Code: Select all

#!/ffp/bin/sh

#Provides:Plex Media Server start
#Downloads and installs PMS, sets PMS enviroment variables, creates PMS directories as needed and starts server

#To be filled. Donwload Synology package, extract  it and copy to /ffp/lib/plexmediaserver

# Set the home of Plex Media Server (installation directory) 
export PLEX_MEDIA_SERVER_HOME=/ffp/lib/plexmediaserver

# Set the directory, where libraries should be searched for first
export LD_LIBRARY_PATH="${PLEX_MEDIA_SERVER_HOME}"

# Set the number of plugins, that can run at the same time 
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6

# Set directory, where the PMS should store the transcodes 
export PLEX_MEDIA_SERVER_TMPDIR=/mnt/HD_a2/plextmpdir

#Checking-Does PLEX_MEDIA_SERVER_TMPDIR exists? If not, it will be created.
if [ ! -d "$PLEX_MEDIA_SERVER_TMPDIR" ]
then
  mkdir -p "$PLEX_MEDIA_SERVER_TMPDIR"
  if [ ! $? -eq 0 ]
  then
    echo "WARNING COULDN'T CREATE $PLEX_MEDIA_SERVER_TMPDIR, MAKE SURE YOU HAVE PERMISSION TO DO THAT!"
    exit 1
  fi
fi

# Set the main directory for Plex (metadata, settings, databases, logs and etc) 
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/ffp/plex

#Checking-Does PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR exists? If not, it will be created.
if [ ! -d "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR" ]
then
  mkdir -p "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR"
  if [ ! $? -eq 0 ]
  then
    echo "WARNING COULDN'T CREATE $PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR, MAKE SURE YOU HAVE PERMISSION TO DO THAT!"
    exit 1
  fi
fi

# Set the maximum stack size value.
export PLEX_MEDIA_SERVER_MAX_STACK_SIZE=3000

# Limits the maximum stack size.
ulimit -s $PLEX_MAX_STACK_SIZE

#Run PMS server
/ffp/lib/plexmediaserver/Plex\ Media\ Server & >/dev/null 2>&1
Above you will find content of two files, on which I am working, trying to adapt PMS on FFP.
Runing them as a PMS_RUN_USER="plex" I am getting user id error. Runing them as a PMS_RUN_USER="nobody" I am getting directory creation permission error. Runing them as a PMS_RUN_USER="root" I am getting "abrakadara some number" at the end of execution, but now directories are created and server starts normally. Then Plex http settings page:[url]http://your_NAS/:32400/web[/url] is also available and fully configurable. Please take a look for mistakes in these scripts.

Mijzelf
Posts: 6205
Joined: Mon Jun 16, 2008 10:45 am

Re: Plex via FFP , managed to get running - Question for Mij

Post by Mijzelf » Thu Jan 24, 2013 11:20 am

barmalej2 wrote:Runing them as a PMS_RUN_USER="plex" I am getting user id error.

Code: Select all

    if ! cat /ffp/etc/passwd | grep ^plex:
    then echo "${PMS_RUN_USER}:x:${PLEXUID}:${PLEXUID}:PLEX Media Server:${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}:/ffp/bin/false" >>/ffp/etc/passwd
    fi
should be

Code: Select all

    if ! cat /ffp/etc/passwd | grep ^${PMS_RUN_USER}:
    then echo "${PMS_RUN_USER}:x:${PLEXUID}:${PLEXUID}:PLEX Media Server:${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}:/ffp/bin/false" >>/ffp/etc/passwd
    fi
Further now you are running 'start_pms' as 'PMS_RUN_USER', but it's certainly possible that it doesn't have the credentials to

Code: Select all

 mkdir -p "$PLEX_MEDIA_SERVER_TMPDIR"
I think it's a better idea to create this directory as root, and chown it.

What is the function of PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR?

barmalej2
Posts: 2387
Joined: Sun Apr 29, 2012 5:24 pm

Re: Plex via FFP , managed to get running - Question for Mij

Post by barmalej2 » Thu Jan 24, 2013 11:59 am

Mijzelf wrote:What is the function of PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR?
It is just a path.
I would call it main data and settings directory of PLEX, where metadata, logs, databases, all plugins resides. At first start PMS creates dir structure and files on PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR path using the source-installation directory (/ffp/lib/plexmediaserver or PLEX_MEDIA_SERVER_HOME in other words). After first run, this dir-PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR can reach up to 120 MB data. You can delete it, and on the next start it will be (and must be, if you wanna get PMS working) recreated. Where can be the best place of this dir? /ffp/share, o better to /mnt/HD_a2?
Last edited by barmalej2 on Thu Jan 24, 2013 1:44 pm, edited 1 time in total.

barmalej2
Posts: 2387
Joined: Sun Apr 29, 2012 5:24 pm

Re: Plex via FFP , managed to get running - Question for Mij

Post by barmalej2 » Thu Jan 24, 2013 12:31 pm

From the debian package:

Code: Select all

#!/bin/sh
case "$1" in
    configure)
	adduser --quiet --system --shell /bin/bash --home /var/lib/plexmediaserver plex
	update-rc.d plexmediaserver defaults
	/etc/init.d/plexmediaserver stop
	/etc/init.d/plexmediaserver start
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

exit 0
If i understand right, according to this script, home dir of plex user should be /ffp/lib/plexmediaserver instead of PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR-/ffp/plex. Will correct this.

Mijzelf
Posts: 6205
Joined: Mon Jun 16, 2008 10:45 am

Re: Plex via FFP , managed to get running - Question for Mij

Post by Mijzelf » Thu Jan 24, 2013 1:44 pm

barmalej2 wrote: home dir of plex user should be /ffp/lib/plexmediaserver
No, /ffp/var/lib/plexmediaserver

barmalej2
Posts: 2387
Joined: Sun Apr 29, 2012 5:24 pm

Re: Plex via FFP , managed to get running - Question for Mij

Post by barmalej2 » Thu Jan 24, 2013 1:47 pm

Mijzelf wrote:
barmalej2 wrote: home dir of plex user should be /ffp/lib/plexmediaserver
No, /ffp/var/lib/plexmediaserver
I leaved this path as it was in your package set. Home dir of plex_run_user is different in different packages of PLEX.

Mijzelf
Posts: 6205
Joined: Mon Jun 16, 2008 10:45 am

Re: Plex via FFP , managed to get running - Question for Mij

Post by Mijzelf » Thu Jan 24, 2013 1:58 pm

Yes, the packages are for various types of NASses, which have divergent filesystem trees. /var could be a ramdrive, and /home could be non-existent.

For this specific directory you can argue it's the homedir of user plex, in which case it belongs in (/ffp)/home, or you could argue it contains changing system data, in which case it belongs in (/ffp)/var. Both are valid.

Did you change anything in the /ffp/lib/plexmediaserver tree? Changed shebangs in .py files? I'll have a look at automatically extracting the Synology package.

barmalej2
Posts: 2387
Joined: Sun Apr 29, 2012 5:24 pm

Re: Plex via FFP , managed to get running - Question for Mij

Post by barmalej2 » Thu Jan 24, 2013 2:52 pm

Mijzelf wrote: Did you change anything in the /ffp/lib/plexmediaserver tree? Changed shebangs in .py files? I'll have a look at automatically extracting the Synology package.
I have not changed anything.

barmalej2
Posts: 2387
Joined: Sun Apr 29, 2012 5:24 pm

Re: Plex via FFP , managed to get running - Question for Mij

Post by barmalej2 » Thu Jan 24, 2013 3:43 pm

[quote="Mijzelf"]should be

Code: Select all

    if ! cat /ffp/etc/passwd | grep ^${PMS_RUN_USER}:
    then echo "${PMS_RUN_USER}:x:${PLEXUID}:${PLEXUID}:PLEX Media Server:${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}:/ffp/bin/false" >>/ffp/etc/passwd
    fi
This doesn't change things with id:

Code: Select all

root@NSA310:~# /ffp/start/plexmediaserver.sh start
plex:x:5000:5000:PLEX Media Server:/ffp/plex:/ffp/bin/false
Starting Plex Media Server: Unknown id: plex
Something is wrong and Plex Media Server can't start
root@NSA310:~# root@NSA310:~# /ffp/start/plexmediaserver.sh start

Mijzelf
Posts: 6205
Joined: Mon Jun 16, 2008 10:45 am

Re: Plex via FFP , managed to get running - Question for Mij

Post by Mijzelf » Thu Jan 24, 2013 3:58 pm

>>/ffp/etc/passwd
Should be >>/etc/passwd.

barmalej2
Posts: 2387
Joined: Sun Apr 29, 2012 5:24 pm

Re: Plex via FFP , managed to get running - Question for Mij

Post by barmalej2 » Thu Jan 24, 2013 9:08 pm

In fact, the scripts are working now:

Code: Select all

root@NSA310:/e-data/2d5ca35d-fc54-468c-92ab-b58d75ba25d3/ffproot/ffp/start# /ffp/start/plexmediaserver.sh start
plex:x:5000:5000:Plex Media Server:/ffp/plex:/ffp/bin/false
Starting Plex Media Server: done
root@NSA310:/e-data/2d5ca35d-fc54-468c-92ab-b58d75ba25d3/ffproot/ffp/start# /ffp/start/plexmediaserver.sh status
Plex Media Server is running...
plex      5611  0.3  7.5 182328 18684 pts/0    Sl   23:00   0:00 /ffp/lib/plexmediaserver/Plex Media Server
plex      5634 15.9 11.4 186288 28280 pts/0    SNl  23:00   0:51 Plex Plug-in [com.plexapp.system] /ffp/plex/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/bootstrap.py --server-version 0.9.7.11.386-d353989 /ffp/plex/Plex Media Server/Plug-ins/System.bundle
plex      5727  0.1  6.0 167400 15024 pts/0    Sl   23:00   0:00 /e-data/2d5ca35d-fc54-468c-92ab-b58d75ba25d3/ffproot/ffp/lib/plexmediaserver/Plex DLNA Server
root      6284  0.0  0.3   2864   932 pts/0    S+   23:05   0:00 /ffp/bin/sh /ffp/start/plexmediaserver.sh status
root      6286  0.0  0.1   1756   368 pts/0    S+   23:05   0:00 grep plex
root@NSA310:/e-data/2d5ca35d-fc54-468c-92ab-b58d75ba25d3/ffproot/ffp/start# /ffp/start/plexmediaserver.sh stop
Stopping Plex Media Server...done
root@NSA310:/e-data/2d5ca35d-fc54-468c-92ab-b58d75ba25d3/ffproot/ffp/start# ps aux | grep plex
root@NSA310:/e-data/2d5ca35d-fc54-468c-92ab-b58d75ba25d3/ffproot/ffp/start#
There is only one issue:
You need to create manualy /ffp/plex directory and chown by plex user.
P. S. 1 How to hide this line:

Code: Select all

plex:x:5000:5000:Plex Media Server:/ffp/plex:/ffp/bin/false
P.S. 2 Tomorrow i will put updated scripts here.
P.S. 3 Good night

Mijzelf
Posts: 6205
Joined: Mon Jun 16, 2008 10:45 am

Re: Plex via FFP , managed to get running - Question for Mij

Post by Mijzelf » Thu Jan 24, 2013 10:33 pm

barmalej2 wrote:P. S. 1 How to hide this line:
By redirecting it to /dev/null. It's the output of grep.
In the construction

Code: Select all

if cat somefile | grep something
then
    someexpression
fi
if evaluates the return value of grep. Grep returns 'true' if it has found something, but it also prints the line(s) containing something to stdout. Here we are only interested in the return value, so you can redirect stdout:

Code: Select all

if cat somefile | grep something >/dev/null
then
    someexpression
fi
P.S. 3 Good night
Good night to you too.

barmalej2
Posts: 2387
Joined: Sun Apr 29, 2012 5:24 pm

Re: Plex via FFP , managed to get running - Question for Mij

Post by barmalej2 » Fri Jan 25, 2013 7:22 am

Today is the day.
/ffp/start/plexmediaserver.sh

Code: Select all

#!/ffp/bin/sh

# PROVIDE: plexmediaserver
# REQUIRE: SERVERS
# BEFORE:

. /ffp/etc/ffp.subr

name="plexmediaserver"
start_cmd="start_plex"
stop_cmd="stop_plex"
restart_cmd="restart_plex"
status_cmd="plex_status"

PMS_RUN_USER=plex
PLEXUID=5000
PID_FILE=/ffp/plex/Plex\ Media\ Server/plexmediaserver.pid
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/ffp/plex


start_plex ()
{
    test -f "/ffp/sbin/start_pms" || exit 0

# Create a user to run Plex Media Server

    if ! cat /etc/passwd | grep ^${PMS_RUN_USER} >/dev/null
    then
    echo "${PMS_RUN_USER}:x:${PLEXUID}:${PLEXUID}:Plex Media Server:${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}:/ffp/bin/false" >>/etc/passwd
    fi


    if [ -f "$PID_FILE" ]
    then echo "Plex Media server is already running..."
         ps aux | grep plex
    exit 0
    else echo -n "Starting Plex Media Server: "
         /ffp/bin/su ${PMS_RUN_USER} -s /ffp/bin/sh -c "/ffp/sbin/start_pms &" >/dev/null 2>&1 && echo "done" || echo "something is wrong and Plex Media Server can't start"
    fi
}

stop_plex ()
{
    if [ ! -f "$PID_FILE" ]
    then echo "It seems that Plex Media Server is not running (no process found)..."
    exit 0
    else echo -n "Stopping Plex Media Server..."
         kill -15 `cat "$PID_FILE"` && echo "done" || echo "something is wrong and Plex Media Server can't be stopped"
    fi
}

restart_plex ()
{
    #sh $0 stop   $stop_cmd maybe a little pause is needed here between commands (didn't tested)-to do
    #sh $0 start  $start_cmd
}

plex_status ()
{
    if [ -f "$PID_FILE" ]
    then echo "Plex Media Server is running..."
         ps aux | grep plex
    else echo "Plex Media Server is not running"
    fi
}

run_rc_command "$1"
/ffp/sbin/start_pms

Code: Select all

#!/ffp/bin/sh

#Provides:Plex Media Server start
#Downloads and installs PMS, sets PMS enviroment variables, creates PMS directories as needed and starts server

#To be filled. Donwload Synology package, extract  it and copy to /ffp/lib/plexmediaserver

# Set the home of Plex Media Server (installation directory) 
export PLEX_MEDIA_SERVER_HOME=/ffp/lib/plexmediaserver

# Set the directory, where libraries should be searched for first
export LD_LIBRARY_PATH="${PLEX_MEDIA_SERVER_HOME}"

# Set the number of plugins, that can run at the same time 
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6

# Set directory, where the PMS should store the transcodes 
export PLEX_MEDIA_SERVER_TMPDIR=/mnt/HD_a2/plextmpdir

# Checking-does PLEX_MEDIA_SERVER_TMPDIR exists? If not, it will be created.
if [ ! -d "$PLEX_MEDIA_SERVER_TMPDIR" ]
then
  mkdir -p "$PLEX_MEDIA_SERVER_TMPDIR"
  if [ ! $? -eq 0 ]
  then
    echo "WARNING COULDN'T CREATE $PLEX_MEDIA_SERVER_TMPDIR, MAKE SURE YOU HAVE PERMISSION TO DO THAT!"
    exit 1
  fi
fi

# Set main data and settings directory for PMS (plugins, metadata, settings, databases, logs and etc) 
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/ffp/plex

# Checking-does PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR exists? If not, it will be created.
if [ ! -d "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR" ]
then
  mkdir -p "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR"
  if [ ! $? -eq 0 ]
  then
    echo "WARNING COULDN'T CREATE $PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR, MAKE SURE YOU HAVE PERMISSION TO DO THAT!"
    exit 1
  fi
fi

# Set the maximum stack size value.
export PLEX_MEDIA_SERVER_MAX_STACK_SIZE=3000

# Limits the maximum stack size.
ulimit -s ${PLEX_MAX_STACK_SIZE}

# Run PMS server
/ffp/lib/plexmediaserver/Plex\ Media\ Server & >/dev/null 2>&1
As I already told, there is one issue:
You need manually create directory /ffp/plex and chown it by user-plex.
First start takes about 20 minutes, until PMS copies and creates a large amount of data (up to 120 MB) to PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR path-"ffp/plex", starts servers, loads plugins, updates them, and etc. Web configuration page is [url]http://Your_NAS_IP:32400/web[/url]

barmalej2
Posts: 2387
Joined: Sun Apr 29, 2012 5:24 pm

Re: Plex via FFP , managed to get running - Question for Mij

Post by barmalej2 » Fri Jan 25, 2013 8:35 am

It would be faster and more reliable if Mijzelf would agree to continue the main work further (script editing i mean). Scripts still needs improvements:
1. Set corect path to PLEX_MEDIA_SERVER_HOME
2. Set corect path to PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR
3. Fill in the part, where donwload Synology package, extract it and copy to PLEX_MEDIA_SERVER_HOME is needed
4. Maybe merge two scripts in to the one, or maybe use conf file for PMS environment variables and startup file.
5. Correct mistakes, which still is, I think.

Mijzelf?

Mijzelf
Posts: 6205
Joined: Mon Jun 16, 2008 10:45 am

Re: Plex via FFP , managed to get running - Question for Mij

Post by Mijzelf » Fri Jan 25, 2013 11:55 am

Yes, OK. I think I'll have time this weekend.

Post Reply