How to install plex (using ports) & if need be; migrate Plex from warden to iocage jails

dureal99d

Contributor
Joined
Aug 3, 2017
Messages
156
(Discliamer): It is impossible to explain an how too based upon every user specific variable. you will have to make adjustments if you have a version of plex or plexpass installed.

however if you are doing a fresh install this should work to a T of course with your edits based upon your pool and desired jail names, ip addresses where obvious.

Create the Jail:

iocage create -n "jail name" -r 11.2-RELEASE ip4_addr="vnet0|jail ip/24" defaultrouter="router ip" vnet="on" allow_raw_sockets="1" boot="on"

once in the jail you want update Package repository:
ee /etc/pkg/FreeBSD.conf

Then:
pkg update && pkg upgrade

now switch directory:
cd /var/db/portsnap

Run Command to install ports:
portsnap fetch extract

Install these packages:
pkg install nano wget sudo

install plex from port:
cd /usr/ports/multimedia/plexmediaserver-plexpass/ && make install clean

To make sure plex starts when you boot the jail:
sysrc plexmediaserver_plexpass_enable=YES

Start your new jail to create the needed folders and stuff:
service plexmediaserver-plexpass start

Stop plex command or stop the Jail:
service plexmediaserver-plexpass stop

IF YOU MUST MIGRATE PLEX TO THE NEW IOCAGE (PRE-11.2 a.k.a. warden):
KEEP IN MIND DEPENDING ON THE SIZE OF YOU DATABASE & HARDWARE IT CAN TAKE A HOUR TO A DAY OR SO TO BACK UP

(note:) You cannot backup your plex data while plex is running.
you must stop plex or the plex jail or your database will be corrupted when restored:

service plexmediaserver stop
while in the jail

or from the legacy interface sop the jail; the choice is yours.

Switch to directory:
if jail is running and plex stopped
cd /usr/local/plexdata-plexpass

if jail is stopped
/mnt/yourdrivepoolname/jails/name of plex jail/usr/local/plexdata-plexpass

run this command while switched into the /usr/local/plexdata-plexpass directory to create a backup archive of your plexdata:
tar -czvf plexbackup.tar.gz Plex\ Media\ Server

once the backup is complete you have 2 options:
Note:
Cool thing is if you need to use your warden plex server at this stage you can as now you will be working in the iocage side of things
Move the file to a place you can find it and move it to the iocage plexdata later:

mv plexbackup.tar.gz /were/you/choose
Or (preferred) you can leave the archive where it was created and move it to the iocage jail using this command
mv plexbackup.tar.gz /mnt/iocage/jails/yourjailname/root/usr/local/plexdata-plexpass

Once the archive is transferred you need to Restore the backup data:
(Again note:) You cannot restore your plex data while plex is running.
you must stop plex or stop the jail or your database will be corrupted when restored:

To move plexbackup.tar.gz from warden location to iocage location:

mv /plexbackup.tar.gz /mnt/iocage/jails/yourjailname/root/usr/local/plexdata-plexpass
once the transfer is complete; switch into iocage jail directory:
cd /mnt/iocage/jails/yourjailname/root/usr/local/plexdata-plexpass
to restore you plex database execute command:
tar -xzvf plexbackup.tar.gz

WARDEN STORAGE POINT TO IOCAGE MOUNT POINT LOCATION RESTORE:

mount point warden:
so lets say you have all your storage points setup in a warden jail lets view an example:

/mnt/mydrivepool/mydataset /mediax

For iocage mount point conversion:
It would look like this:

iocage fstab -a yourjailname "/mnt/mydrivepool/mydataset /mediax nullfs rw 0 0"

Once you have your iocage mount points restored to match what you had in warden jail storage:

Start Plex to verify all is well and works as it should:

service plexmediaserver_plexpass start

Navigate to your jail:
http://youriocagejailip:32400/web/index.html#


CLEAN UP AND REMOVE WARDEN JAIL:

Remove Plex only after verifying that the new restore works:

pkg remove plexmediaserver
sysrc -x plexmediaserver_enable

Assuming all went well remove the warden jail in the legacy interface

And if all is well wala toast it up!!!!!!

TO UPDATE PLEX USING PORTS:
Switch to directory:

cd /var/db/portsnap

Run Command to update ports:
portsnap fetch update

uninstall current plex:
(This can be done while your plex server is still running with no down time)

cd /usr/ports/multimedia/plexmediaserver-plexpass/ && make deinstall clean

Then run this command to install the newest version of plex:
cd /usr/ports/multimedia/plexmediaserver-plexpass/ && make install clean

AND YOUR GOLDEN:
 
Last edited:

samuel-emrys

Contributor
Joined
Dec 14, 2018
Messages
136
Thanks for the guide mate! I have a question though:
Why do you use both pkg and ports? These achieve largely the same function, where the pkg repository generally lags a few days behind ports. It seems to me like the installation and upgrading portion of this guide could be simplified significantly by just performing the upgrade using pkg, and skipping the use of ports altogether:
pkg update && pkg upgrade plexmediaserver-plexpass
service plexmediaserver_plexpass restart

Ports provide some advantages (faster updates, ability to choose compilation options), but I think it gets confusing when you mix ports and pkg together. For instance, the first portion of the guide suggests navigating to /usr/ports/multimedia/plexmediaserver-plexpass/, and then immediately after running pkg install plexmediaserver-plexpass - all that you need to do here is run the second command, because you're installing from pkg not the port you've just fetched. For consistency, if you want to provide a ports guide and not a pkg guide, perhaps it would be worth changing this second command to make install to install the port.

As for the migration portion of the guide, I think a lot of people will get good value from this, great work.
 

dureal99d

Contributor
Joined
Aug 3, 2017
Messages
156
Thanks for the guide mate! I have a question though:
Why do you use both pkg and ports? These achieve largely the same function, where the pkg repository generally lags a few days behind ports. It seems to me like the installation and upgrading portion of this guide could be simplified significantly by just performing the upgrade using pkg, and skipping the use of ports altogether:
pkg update && pkg upgrade plexmediaserver-plexpass
service plexmediaserver_plexpass restart

Ports provide some advantages (faster updates, ability to choose compilation options), but I think it gets confusing when you mix ports and pkg together. For instance, the first portion of the guide suggests navigating to /usr/ports/multimedia/plexmediaserver-plexpass/, and then immediately after running pkg install plexmediaserver-plexpass - all that you need to do here is run the second command, because you're installing from pkg not the port you've just fetched. For consistency, if you want to provide a ports guide and not a pkg guide, perhaps it would be worth changing this second command to make install to install the port.

As for the migration portion of the guide, I think a lot of people will get good value from this, great work.
your right i was not thinking and have created confusion, let me rework this
 

Cyberfly

Cadet
Joined
Jan 1, 2019
Messages
7
Awesome, that is exactly what I needed. Thank you very much.

I found a few minor things:

1) One should check where the iocage stuff lives physically and change it ahead of time if necessary.
2) for me, at least, it is always plexmediaserver_plexpass, not plexmediaserver-plexpass
To make sure plex starts when you boot the jail:
sysrc plexmediaserver-plexpass_enable=YES
Start your new jail to create the needed folders and stuff:
service plexmediaserver-plexpass start
Stop plex command or stop the Jail:
service plexmediaserver-plexpass stop
IF YOU MUST MIGRATE PLEX TO THE NEW IOCAGE (PRE-11.2 a.k.a. warden):
KEEP IN MIND DEPENDING ON THE SIZE OF YOU DATABASE & HARDWARE IT CAN TAKE A HOUR TO A DAY OR SO TO BACK UP


(note:) You cannot backup your plex data while plex is running.
you must stop plex or the plex jail or your database will be corrupted when restored:

service plexmediaserver stop

3) for consistency, plex should be replaced by yourjailname, here:
For iocage mount point conversion:
It would look like this:

iocage fstab -a plex "/mnt/mydrivepool/mydataset /mediax nullfs rw 0 0"

4) I tried making the update a cron job. For this I created a sh script, restarting the service for good measure:
Create and open a new sh file:
ee updateplex.sh
Copy this code inside and save:
"cd" /var/db/portsnap "portsnap" fetch update "sed" -i '.bak' 's/kill $sig_stop ${_PLEX_CHILDREN}/kill -9 ${_PLEX_CHILDREN}/g' '/usr/local/etc/rc.d/plexmediaserver_plexpass' "service" plexmediaserver_plexpass stop "cd" /usr/ports/multimedia/plexmediaserver-plexpass/ && "make" deinstall clean "cd" /usr/ports/multimedia/plexmediaserver-plexpass/ && "make" install clean "service" plexmediaserver_plexpass start
Create a cron job with the following command and run however often you want (e.g. once a week) sometime in the middle of the night:
iocage exec yourjailname sh root/updateplex.sh

Edit: seems root/updateplex.sh is now needed as a path to run the script in the root folder.
Edit2: There was an issue where the service would not stop completely, preventing the updating script from completing. I added the line
"sed" -i '.bak' 's/kill $sig_stop ${_PLEX_CHILDREN}/kill -9 ${_PLEX_CHILDREN}/g' '/usr/local/etc/rc.d/plexmediaserver_plexpass'
to allow the stop command of the service to force kill the remaining processes as suggested in this post by a plex employee.
 
Last edited:

dureal99d

Contributor
Joined
Aug 3, 2017
Messages
156
Awesome, that is exactly what I needed. Thank you very much.

I found a few minor things:

1) One should check where the iocage stuff lives physically and change it ahead of time if necessary.
2) for me, at least, it is always plexmediaserver_plexpass, not plexmediaserver-plexpass


3) for consistency, plex should be replaced by yourjailname, here:


4) I tried making the update a cron job. For this I created a sh script, restarting the service for good measure:
Create and open a new sh file:
ee updateplex.sh
Copy this code inside and save:
"cd" /var/db/portsnap "portsnap" fetch update "service" plexmediaserver_plexpass stop "cd" /usr/ports/multimedia/plexmediaserver-plexpass/ && "make" deinstall clean "cd" /usr/ports/multimedia/plexmediaserver-plexpass/ && "make" install clean "service" plexmediaserver_plexpass start
Create a cron job with the following command and run however often you want (e.g. once a week) sometime in the middle of the night:
iocage exec yourjailname sh updateplex.sh
Awsome update script
 

paradoxiom

Patron
Joined
Jun 16, 2015
Messages
239
I've got my Plex Media Server user data in its own dataset and I mount the dataset to
/mnt/Orbital-System/iocage/jails/plex-plexpass/root/Plex Media Server

All has been fine doing this. I broke the server somehow yesterday (permissions I think) and so I just decided to install the plugin and move my mount points over, then manually transfer the latest BSD release via winscp.

I start the plex server, but it doesn't work. There aren't even any log files, and it doesn't say plex exited - it's still running and I can see it on my router but can't access the page.

Before I updated it I ran it once to check it worked and it did - something in the user settings must be causing it to not work but I can't figure out what it is. My only guess is the

MachineIdentifier="f123b945-42435b1-8567390e"
ProcessedMachineIdentifier="7f54d4ced576c3f5eb4f082d91e8efc4"
AnonymousMachineIdentifier="c97c4916-13eb3a94-ff4574e7ed4921"

lines from the pref.xml file. any ideas?

Edit: I went to plugins and hit update plugin on the new install, after that was done it started up fine, but it's still using the old version now - how come when I overwrite the install with the latest version it just stops working? that's how I've done it for ages now.

Thanks again
 
Last edited:
Top