Plex Media Server - Linux installation packaging update - Issues

Maybe let’s explore other ways to detect if we’re standing inside a container, so you don’t have to keep a tab of all the init’s binaries:

  • the /.dockerenv file is present
  • check /proc/1/cgroup for container values
~❯❯❯ cat /proc/self/cgroup
11:freezer:/user/root/0
10:memory:/user/root/0
9:cpuset:/
8:pids:/user.slice/user-1000.slice/session-38202.scope
7:cpu,cpuacct:/user.slice
6:blkio:/user.slice
5:rdma:/
4:perf_event:/
3:net_cls,net_prio:/
2:devices:/user.slice
1:name=systemd:/user/root/0
0::/user.slice/user-1000.slice/session-38202.scope
~❯❯❯ docks enter linux
Warning: this is a temporary container
root@897672d02272:/data# cat /proc/self/cgroup
11:freezer:/docker/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
10:memory:/docker/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
9:cpuset:/docker/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
8:pids:/docker/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
7:cpu,cpuacct:/docker/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
6:blkio:/docker/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
5:rdma:/
4:perf_event:/docker/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
3:net_cls,net_prio:/docker/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2:devices:/docker/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1:name=systemd:/docker/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0::/system.slice/containerd.service

for lxc it will be something like /lxc/**

What do you think?

1 Like

I actually have LXC but I didn’t think of examining the cgroup. GREAT catch.

Brainstorm with me?

if [  $( cat /proc/1/cgroup | grep docker | wc -l ) -gt 0 ];  then
   echo We're in a Docker container.
fi

If I’m going to enhance fully, which would is best for ?

  1. main package
  2. VM
  3. Docker
  4. LXC

/proc/1/environ seems the most stable way to detect LXC

1 Like

systemd-detect-virt is fairly comprehensive: https://github.com/systemd/systemd/blob/master/src/detect-virt/detect-virt.c

This also might be a huge help: https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/facts/virtual/linux.py

Thanks for the suggestions but please remember,

I can only go on what will be known to exist on every possible system.

I can’t carry any dependencies with me because the package scripts are architecture independent.

If the hypervisor is masked, I won’t know it’s in a VM.

I’ve decided to go with what the kernel tells me in /proc.
Everything there has been validated by the kernel.

The changes have been made, tested, and are already in Engineering and QA hands for review & inclusion.

1.18.6 PlexPass is a few days away so you will see the results of today very shortly.

I think it’s positive, since it gives a consise and convenient way to identify the configuration at hand (see our discussion on hw acceleration).

This should be invaluable for less technical users, to your point, in particular when troubleshooting is required.

I believe that more detail would be beneficial for such purposes.

Jut updated an Ubuntu 18.04 server with 1.18.5.2309 and although no errors displayed during the apt upgrade, the plexmediaserver was NOT restarted after the upgrade. I had to manually issue a this command to get it running.

sudo systemctl start plexmediaserver

Is this a known issue or should I be looking some where for a clue on what went wrong?

1 Like

@helphand

Can you provide more information please?

I ask because I expressly manually start it during this upgrade regardless of previous state.

Do you still have /tmp/plexinstall.log available? I would like to see it.

Sorry, but no /tmp/plexinstall.log isn’t there. I just finished two more Ubuntu 18.04 updates and they also had the identical issue, no restart of the server after the update. I also did a raspberrypi update but that one worked, the server was correctly restarted.

One more data point, all three Ubuntu servers were in a ‘require a reboot’ state from prior kernel updates. Not sure if that makes any difference.

Hi. I’ve found and locally fixed a bug with the preinstall script not correctly parsing my override.conf

Systemd docs describe their config as “ini-style files”, so my automation uses ansible’s ini file generator to create the override.conf. Systemd handles it fine, but the new preinst does not. The problem is spaces between the key and the value, ie

Environment = "PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=..."

Changing line 76 of preinst (in GetValue()) to the following seems to work:

  Retval="$(grep -v ^# $2   | sed -e 's/^export //' | sed -e 's/^Environment\s\?=\s\?//' | \

The Preinstall writes /tmp/plexinstall.log at the end of the evaluation stage.
When package installation is complete, state is restored
(while in transition - force start after install is asserted)

Enable/Disable state is however observed now. I do not alter Enable/Disable state which had been previously done in older packaging. The only time I assert Enable is during a fresh installation on a new machine.

If the server was rebooted after installation and was disabled, it will not start at boot.

Can you provide me a full string of what is in that override.conf file?
I want to parse better and raise the warning if possible.

Please explain what you’re doing with the GetValue() change.
It looks like you’re relaxing the syntax check?

IMHO, which I’m happy to discuss, they may be Item-Value pairs, they don’t carry the freedom of the old Window INI files. Primary example:

Environment="PLEX_APP_SUPP_DIR=/location with spaces/here"
They follow sh syntax instead tcsh syntax AFAIK

Still, even though I didn’t detect the fault (which I should), that configuration would never have run even before, true?

Thanks for looking at this. The full string is

[Service]
Environment = "PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/home/pi/plex/Library/Application Support"

From man systemd.syntax

The syntax is inspired by XDG Desktop Entry Specification[1] .desktop files, which are in turn inspired by Microsoft Windows .ini files.

And the XDG Deskop Entry Spec says:

Space before and after the equals sign should be ignored; the = sign is the actual delimiter.

To highlight (and perhaps improve on) the change

sed -e 's/^Environment=//'          # Original file
sed -e 's/^Environment\s\?=\s\?//'  # My first attempt above
sed -e 's/^Environment\s*=\s*//'    # On reflection, this might be better 

Previously that command was stripping out the “Environment=” from the start of lines in the override.conf file (before further processing to actually get the value after the environment variable name). But if there are spaces before or after equals, the pattern doesn’t match, so doesn’t get stripped. This messes up the subsequent processing.

\s\? matches zero or one whitespace character (apparently in the default sed mode you have to escape the standard regex ? symbol). So in this case it works for lines with or without spaces around the first ‘=’.

The \s* version does the same but also works if there are multiple spaces before and/or after the ‘=’.

The systemd overrides were working fine before (and I think still are because this is causing my apt upgrade to fail):

PlexMediaServer install: Pre-installation Validation.  
grep: pi: No such file or directory
PlexMediaServer install: Error: Directory ' PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR' used in /etc/systemd/system/plexmediaserver.service.d/override.conf  does not exist.  
dpkg: error processing archive /var/cache/apt/archives/plexmediaserver_1.18.5.2309-f5213a238_armhf.deb (--unpack):
 new plexmediaserver package pre-installation script subprocess returned error exit status 1

I like that but I also must be very careful of processing the shell variable syntax in /etc/default/plexmediaserver which is strict Name=Value (no spaces).

If spaces made their way in to an Init-based system then I wouldn’t be detecting bad customization data which I have commited to provide in this packaging upgrade.

Where is this “ansible INI” script you speak of? I ask because this is the first time I’ve heard of it. Google tells me it’s another Linux variant ?

Ah, ok. If GetValue is being used for another file type as well I guess it might not be not so straightforward.

Ansible is one of those “Infrastructure as code” frameworks for deploying/configuring machines. It’s based on python and is cross-platform. It has an INI module that I was using to generate the override.conf format for me. I can fairly easily just template the file instead if it’s going to be tricky to support with spaces.

I have a question.

Why are you using a commercial IT deployment system such as Ansible for a Home product such as Plex?

Are you attempting to revive Plex Cloud?

Mainly just to learn about Ansible (I’m a software engineer). It’s probably overkill but I use it to set up and update two raspberry pis with Plex and a few other services. One for me and one for my parents. It also came in very handy to get back up and running quickly when I upgraded my raspberry pi recently.

I’ve not heard of Plex Cloud.

Which distribution of Linux is this using?

Raspberry Pi’s “Raspbian”, based on Debian

Thanks.

I’ll bring this up to the team next week when we meet.
We already know there is room for, and have planned to implement, additional improvements.

1 Like