Scripted installation of Plex Media Server

Introduction

I’ve writen a simple script to automate installation of Plex Media Server. Like other scripts I’ve done, you’ll download the script, create a small configuration file, run the script, and your jail is up and running.

Why bother?

I’ve said for a long time that Plex installation is trivial, requiring only three commands once the jail is created (pkg install plexmediaserver, sysrc plexmediaserver_enable=YES, service plexmediaserver start). While this remains true, it doesn’t account for a few “best practices”:

  • The Plex metadata is stored inside the jail. If the jail needs to be rebuilt for some reason, you’ll lose it.
  • The package repository is by default set to quarterly, meaning that the Plex Media Server package will only be updated that often. Many Plex users have a near-pathological desire to have their installation as up-to-date as possible, so this won’t do.
  • There’s nothing in those three commands that sets up automatic updates to the installed packages.

This script addresses these issues–the Plex metadata is stored outside of the jail, the jail is configured to use the latest repository, and a cron job runs weekly to update the installed packages in the jail.

Installation and use

See:

5 Likes

Looks like a nice alternative to the plugin for those that don’t want to do a manual install.

That’s the idea–and to keep the data out of the jail in case the jail gets hosed and needs to be rebuilt.

Thank you for providing this solution. I’m a newbie and just tried this out but after getting a message saying plex successfully created I get a VNET failure". Please can you point me in the direction of whatever pre-config i need to do?

Thanks

Sorry for the delay in responding. Networking in iocage jails can be a little tricky–could you post more of the command output (or, better yet, the entire output of the script, along with the contents of the plex-config file)?

Hi Dan,

Thanks for replying and sorry for my very slow response. I wasn’t sure how to get detailed output but found that by adding > filename after the command gave a verbose listing although it didn’t seem to write to file although I could copy/paste it (as you can see I’m a complete newbie on this).

Here is the plex-config file detail:
JAIL_IP=“192.168.1.148”
DEFAULT_GW_IP=“192.168.86.1”
POOL_PATH="/mnt/Pool1"
USE_PLEXPASS=“1”

Here is the output generated
plex successfully created!
Failed to create jail

and here is the verbose output generated onscreen when > filename is used
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/iocage_cli/create.py”, line 164,in cli
basejail=basejail, thickjail=thickjail, empty=empty)
File “/usr/local/lib/python3.6/site-packages/iocage_lib/iocage.py”, line 611,in create
clone=clone,
File “/usr/local/lib/python3.6/site-packages/iocage_lib/ioc_create.py”, line 87, in create_jail
return self._create_jail(jail_uuid, location)
File “/usr/local/lib/python3.6/site-packages/iocage_lib/ioc_create.py”, line 555, in _create_jail
self.create_install_packages(jail_uuid, location, config)
File “/usr/local/lib/python3.6/site-packages/iocage_lib/ioc_create.py”, line 600, in create_install_packages
silent=True)
File “/usr/local/lib/python3.6/site-packages/iocage_lib/ioc_start.py”, line 67, in init
self.start_jail()
File “/usr/local/lib/python3.6/site-packages/iocage_lib/ioc_start.py”, line 503, in start_jail
_callback=self.callback)
File “/usr/local/lib/python3.6/site-packages/iocage_lib/ioc_common.py”, line 90, in logit
_callback(content, exception)
File “/usr/local/lib/python3.6/site-packages/iocage_lib/ioc_common.py”, line 64, in callback
raise callback_exception(message)
RuntimeError:
Stopped plex due to VNET failure

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/iocage", line 10, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/iocage_cli/create.py", line 184,in cli
    "message": err
  File "/usr/local/lib/python3.6/site-packages/iocage_lib/ioc_common.py", line 90, in logit
    _callback(content, exception)
  File "/usr/local/lib/python3.6/site-packages/iocage_lib/ioc_common.py", line 64, in callback
    raise callback_exception(message)
RuntimeError:
Stopped plex due to VNET failure

Please let me know if you need this in another format or created in another way.

Thanks

This looks like your problem–the JAIL_IP needs to be on the same subnet as DEFAULT_GW_IP. That is, JAIL_IP needs to be 192.168.86.something if your router’s IP address really is what you say there.

Yes, that worked. I can’t believe /i missed something so obvious. Thanks very much.

Outstanding, nice that it was something simple. Enjoy!

I just tried to use this script and the script fails.
it seems the jail is not getting DNS. outside of the jail DNS works. what am i doing wrong?

root@Atlas[/mnt/Storage/Scripts/freenas-iocage-plex]# ./plex-jail.sh
plex successfully created!

Testing SRV response to FreeBSD
pkg.freebsd.org's SRV record could not be verified.

Testing DNSSEC response to FreeBSD
pkg.freebsd.org could not be reached via DNSSEC.

Testing DNS response to FreeBSD
pkg.freebsd.org could not be reached via DNS, check your network
Failed to create jail

plex-config

JAIL_IP="192.168.10.200"
DEFAULT_GW_IP="192.168.10.1"
POOL_PATH="/mnt/Storage/AppData"

Which version of FreeNAS are you using?

I am sorry i forgot to say, I am on FreeNAS-11.2-U7

Should this work on 11.3-RELEASE?

I get this error:

  • iocage create --name plex -p /tmp/pkg.json -r 11.3-RELEASE-p5 ‘ip4_addr=vnet0|192.168.1.4/24’ ‘defaultrouter=192.168.1.1’ ‘boot=on’ ‘host_hostname=plex’ ‘vnet=on’
    11.3-RELEASE-P5 was not found!
  • echo ‘Failed to create jail’
    Failed to create jail
  • exit 1

I’m going to try hardcoding RELEASE to “11.3-RELEASE”.

That should do it in the short term–thanks for the reminder to update the script to strip out the patch level (which previous releases didn’t report).

My metadata is being written to the default location, not the one specified in plex-config:

root@bigserver[~/freenas-iocage-plex]# cat plex-config
JAIL_IP=“192.168.1.4”
DEFAULT_GW_IP=“192.168.1.1”
POOL_PATH="/mnt/space1"
JAIL_NAME=“plex2”
USE_PLEXPASS=“1”

  • iocage fstab -a plex2 /mnt/space1/plex_data /config nullfs rw 0 0
  • iocage exec plex2 ‘plexmediaserver_plexpass_support_path=/config’

root@bigserver[~/freenas-iocage-plex]# iocage exec plex2 ls -ld /config
drwxr-xr-x 2 plex plex 3 Feb 5 02:44 /config

/mnt/space1/plex_data is created and added as a mount point to the jail at /config, but
it is empty and the data is being written to the default location: /usr/local/plexdata-plexpass/Plex Media Server/Metadata/“Library Names”

What’s the output of iocage exec plex2 sysrc -a?

Edit: OK, I see the problem–I’d left the sysrc command out in the script. That’s fixed now, but for your installation, run iocage exec plex2 sysrc plexmediaserver_plexpass_support_path=/config. You can then stop plex, move your existing data into /config, and restart it.

1 Like

This should also be fixed now. The one thing this doesn’t do is install a 11.3 jail on 11.2-U7 (which is possible and would be preferred), but the jail should still install now.

Is this the place for bug reports, suggestions, and feature suggestions or should I send you email?

This is a good place; another possibility would be to raise an issue on the GitHub page–but this keeps the discussion in one place.

hi dan,
I upgraded my freenas box to version 11.3, including jails.
before the update, i had installed this script, that worked like a charm.
Now, after the upgrade, I notice that plex is at version 1.18.4.2171 and notified that there is an update.
Could this be a crontab problem? has anyone had the same problem?
thax to all