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.

Bugs?


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


Suggestions:


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
  PLEXPASS="-plexpass"

  #This would be used to do something similar in the configuring PLEX section
  _PLEXPASS="_plexpass"
fi
cat <<__EOF__ >/tmp/pkg.json
{
	"pkgs":[
	"plexmediaserver${PLEXPASS}"
	]
}
__EOF__

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
__EOF__
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.

Phil

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
? EOF
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:~ #

Good.
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?

I made it through the install without issue and everything is running. However, I can’t seem to figure out the proper permissions to the share… rather the right user/group to assign rights to. I set @everyone to read access and that worked to view movies I had uploaded. I then tried auto uploading from my phone and that only worked if I gave everyone write access. So, I know it’s a permission issue. I tried to figure out the Plex User name/id but don’t know enough about FreeBSD to know where to look. Any help would be appreciated.

Your base FreeNAS system doesn’t have a user for Plex, which means that assigning permissions will be tricky. Your best bet is to create one, with a username of plex and a user ID of 972. Then you can add permissions for that user to write to your media dataset, rather than @everyone.

1 Like

Good idea. I’ve added this:

Note that if the script creates $PLEX_CONFIG_PATH, it will create it as a directory, not as a dataset. This means that it will not appear in, e.g., the Storage section of the FreeNAS GUI, where you could easily see how much space it’s using, compression ratio, etc. If you want these capabilities, you should create the dataset before running the script, and then ensure that $PLEX_CONFIG_PATH is set appropriately.

Hi, I am reading though the script, as I like to understand them before I use them, and have a couple of questions, which I hope you can answer.

  1. The command to create the Jail (line 166) has ${DEVFS_RULESET} on it. I understand the rest but not sure what this is, can you expand my knowledge please by explaining it.

  2. I think I understand that lines 195 & 198 set the Plex MetaData directory to /config, which is where you mount the dataset holding this data, is that right?

  3. Not sure what the directory /configs is used for, can you explain?

  4. The package plexmediaserver_plexpass used to be for Plex Pass users for their additional features, has this now merged into the plexmediaserver package with the plexmediaserver_plexpass just being used as a BETA now?

Thanks,
Jonathan

This is used with the hardware transcode setup.

Correct, though whether it’s a dataset or a directory is up to the user.

It’s used temporarily for files that need to be copied into the jail–pkg.conf and the package update script.

Yes. The “normal” package provides the PlexPass features if you’re signed in to a PlexPass account, and doesn’t if you aren’t. The “Plexpass” package now acts as a beta. It gives early access to some new features (at least at times), but isn’t as stable.

1 Like