Scripted installation of Plex Media Server

It isn’t unusual for there to be a bit of delay from Plex releasing a new version to a FreeBSD package being available for that version–I wouldn’t expect it to be more than about a week, though.

I’m new to GitHub and haven’t worked through the tutorial yet, but I didn’t see any way to message there other than your email link so I’ll use this forum. I assume that once I’ve figured it out that there is a way to make changes and then make them available for review?

That mechanism in GitHub is called a Pull Request. It’s a little convoluted, but it works well.


The script mentions nextcloud-config in two comments, I assume that this is due to code reuse?

I don’t think that the crontab sed works if you’re using Plex Pass. It’s set up for non-plexpass:

18 3 * * 0 pkg upgrade -y && service plexmediaserver restart

So the sed should be moved to the Plex Pass section of if and add -plexpass rather than trying to remove a -plexpass that isn’t there.

Update the comment at the top of the file to mention 11.3


If /config is shared by your other scripts how about using a more self documenting name like /config-plugins and putting it in /usr/local…? (I’ve always thought of / as kind of a reserved space.) If it’s not then I have code that does the null mount on the default /usr/local/plexdata[-plexpass].

Use a feature test to set or unset variables so code doesn’t have to be duplicated:

if [ ${USE_PLEXPASS} -eq 1 ]; then

  #This would be used to do something similar in the configuring PLEX section
cat <<__EOF__ >/tmp/pkg.json

I’ve written some code to validate the pool name using zpool list and that changes the configuration setting so that the user only specifies the name and not the full path to the pool. This is more ZFS like in that is uses the ZFS namespace. The pool’s mount point is then derived also using zpool list.

Possible Features:

Provide the option to make plex_data a dataset so that ZFS stuff like quotas and replication can be used on it. (I have code that does this.)

Option to use DHCP for those who like to use their router to assign reserved IP addresses. (I’ve started this.)

Once I get GitHub figured out I’m willing to do any of the above, just let me know.

thanx for clarification

Good points in all cases, fixed.

On the suggestions:

  • I like the use of variables you’re suggesting; that could clean things up considerably–you’ll notice that my scripting isn’t exactly elegant.
  • I’m not married to putting the metadata in /config inside the jail, though that is kind of a convention in a number of the jail guides on the “official” forum. I’d be concerned that putting it in /usr/local/ would make it look too much like part of the jail’s filesystem, when the point is for it to not be there.
  • Validating the pool name would be good, but I’m not sure there’s a whole lot of value to using the ZFS namespace rather than filesystem paths–though I’d be interested to hear other opinions on this.
  • plex_data can already be a dataset, and it can be located anywhere and called anything. The script doesn’t create it as a dataset, though, and I’m not sure I’d want to be doing that at the CLI (messing with datasets behind the GUI’s back is generally discouraged).
  • DHCP would be a good option.

As @pjrobar pointed out above, there’s actually an error in the cronjob that I’d missed. To fix it, enter the jail with iocage console plex, then run the following:

cat <<__EOF__ >cronjob
#Upgrade all installed packages and restart Plex
18 3 * * 0 pkg upgrade -y && service plexmediaserver-plexpass restart
crontab cronjob

Only Plex Pass users need to do this, in fact this “fix” will break non-Plex Pass setups.

Also, this fix can be applied manually using confab -e to edit the file.


Correct, and I thought I’d seen @bermau say he was using Plex Pass–but as I review the posts in this thread I don’t see it now.

Also correct (though I assume you meant crontab -e), if you’re willing to mess with vi. I’m a wimp and use nano, but it isn’t installed in this jail by default and I didn’t think it’d be worth installing for just a one-line edit.

Hi Dan,
yes I use Plex Pass.

I ran the command, the output was:

root@plex:~ # cat <<EOF >cronjob
? #Upgrade all installed packages and restart Plex
? 18 3 * * 0 pkg upgrade -y && service plexmediaserver-plexpass restart
root@plex:~ # crontab cronjob
root@plex:~ #

Is it ok?

Yes, that looks fine. If you want to confirm, run crontab -l.

root@plex:~ # crontab -l
#Upgrade all installed packages and restart Plex
18 3 * * 0 pkg upgrade -y && service plexmediaserver-plexpass restart
root@plex:~ #

Thanx again.

1 Like

Hi danb35,

If there is valid Plex configuration data outside the jail and the jail is hosed and the script run again, will the data in PLEX_CONFIG_PATH remain intact or will it also get hosed as part of rerunning the script?

My script doesn’t do anything to the contents of PLEX_CONFIG_PATH–any data in there should be preserved.

1 Like

I wish I hadn’t been so stubborn about sticking close to plugins in the FreeNAS GUI. This script addresses all the issues you’ve identified with the Plex plugin. Love it!

Just one observation. This is an extract from the installation notes…

$PLEX_CONFIG_PATH need not exist before running this script; if it doesn’t, the script will create it. The script will also set ownership of that directory to the user/group IDs for Plex Media Server. If this directory already exists, it must not be using Windows permissions.

When I first ran the script, I went looking for the directory in the FreeNAS GUI. It wasn’t visible. I found it through the Shell instead. I decided to destroy the created jail and remove the directory. I then created $PLEX_CONF_PATH beforehand as a dataset rather than as a directory. The advantage for me is that I can easily see the size of Plex configuration data from the GUI under Storage > Pools. I found this step useful.

EDIT: I just spotted some discussion about this further up in the thread. While I understand your concern about not creating the dataset within the script, I wonder whether the installation notes could be revised to make this point more visible?