PMS stops on package update - RPM linux

Server Version#: 1.19.1
Player Version#: -

This is a message for the devs. Every time the RPM package gets updated it stops the service. This is because the preuninstall scriptlet lacks the check when the package is being updated. This is the current script:

  # Stop PMS and wait for it to die.
  systemctl stop plexmediaserver
  sleep 3

  exit 0

you need to add this check:

  if [ $1 -eq 0 ] ; then 
        # Package removal, not upgrade 
        # Stop PMS and wait for it to die.
        systemctl stop plexmediaserver
        sleep 3

        exit 0
  fi

This is commented here:

Thanks for your support!

Thanks for reaching out.

Yes, I’m aware of it.
There’s a lot it doesn’t take into consideration.

If you look at %post, you’ll see where the existing is supposed to always restart after upgrade if the run-state was set. Yes, it’s broken right there.

%post

# Create default PMS library directory for user 'plex' if it doesn't exist.
if [ ! -d /var/lib/plexmediaserver ]; then
  mkdir /var/lib/plexmediaserver
  chown plex:plex /var/lib/plexmediaserver
fi

# Add PMS SELinux policy file if SELinux is present and not disabled.
if [[ -f /usr/sbin/getenforce && ! $(/usr/sbin/getenforce | grep -i Disabled) ]]; then
    semodule -i /usr/lib/plexmediaserver/plexrsync.pp
fi

case "$1" in
  1) # Inital installation.

    # Inform systemd to reload and pick up the new service file.
    systemctl daemon-reload

    # Enable (by default) for auto start with reboot, then start.
    systemctl enable plexmediaserver
    systemctl start plexmediaserver
  ;;

  2) # Upgrade installation.

    # Inform systemd to reload and pick up any changes to service file.
    systemctl daemon-reload
    sleep 2

    # Restore previous run state.
    if [ -f /tmp/.plexmediaserver.install.tmp ]; then
      systemctl start plexmediaserver
      rm  -f /tmp/.plexmediaserver.install.tmp
    fi
  ;;
esac

I’m replacing all that now. I don’t know if you’ve seen the new installer for Debian which was just completed but that’s coming to RPM’s next with exception of the SYSV init support (not seen any justification to have it).

If you have time, look at the debian version, and spot anything of special consideration for RPMs, please let me know. Now’s the time to get it in the new scripting.

I don’t see a problem in the %post. The problem with the upgrade is that yum or dnf uninstalls the previous version after upgrade. That means that %preuninstall will unconditionally stop the service (after being started in the %post). The if I sent you in the previous message stops that from happening.

It’s dependent on that. Now go look. The %pre writes it

# Check if this an upgrade to an existing PMS installation.
if [ "$1" = "2" ]; then

  # Quietly remove status flag incase previous installation was aborted.
  rm -f /tmp/.plexmediaserver.install.tmp

  # As this is an upgrade, obtain PMS running status and save it until %post.
  systemctl status plexmediaserver | grep 'Active: active' >/dev/null
  if [ $? -eq 0 ]; then
    touch /tmp/.plexmediaserver.install.tmp
  fi

  # Stop PMS.
  systemctl stop plexmediaserver
fi

So where’s the file disappearing to unless PMS is stopped before %pre runs?

I think we are talking about different things, this is the sequence:

  1. rpm installs the new package and executes %pre and %post. This is fine. %post sees the file /tmp/.plexmediaserver.install.tmp that %pre has created and starts the service. From here everything is fine.
  2. After the new rpm has been installed, rpm uninstalls the previous version. Therefore, %preun and %postun runs. %preun stops PMS unconditionally, and therefore leaves the service down.

I’m sorry.

I’m not saying it right but understand it’s exactly that.

Correct me if I’m wrong but %preun should know that an update just occurred (the args) and not touch the service state?

That is what the conditional would protect ?

Going by this chart
Screenshot from 2020-04-12 00-56-05

One thing not clear to me is the difference between cleanup and actual uninstall.

“$1” = the number of packages which are / will be installed when complete?

Meaning:
0 = full uninstall so stop it.
1 (or 2) = new install (or upgrade) so don’t stop it.

Yes, exactly. $1 in %pre and %post for the upgrade is 2 because until the uninstall of the previous version occurs, for the moment there are 2 packages of the same name in the system. $1 in %preun and %postun is 1 because after removal of the old one, only 1 will be left installed (the new one).

You can see for example the %preun of package httpd:

if [ $1 -eq 0 ] ; then 
        # Package removal, not upgrade 
        systemctl --no-reload disable --now httpd.service htcacheclean.service httpd.socket &>/dev/null || : 
fi

Or for example, the %preun of the package openssh-server:

if [ $1 -eq 0 ] ; then 
        # Package removal, not upgrade 
        systemctl --no-reload disable --now sshd.service sshd.socket &>/dev/null || : 
fi

I read in the docs about %preun being called twice?
Did I misread?

I need to know when it’s OK to stop (so I can freely update the binaries) and also do run-state detection then restart after (which will happen in post)

@oht0Ko5i

I want to close the loop and thank you for pointing this out.

The changes have been made;

tested by QA.

Scripting change approved, in the master CM branch and on its way to production.

fingers crossed— The next PlexPass release will have it

@oht0Ko5i and all reading here.

PMS 1.19.4 will contain the fix for RPM packaging stopping PMS during post-upgrade cleanup.

All reviews and tests have passed. I committed the changes to the master release myself today.

Thanks for your support Chuck.

Followup question if I may?

When do you want the upgraded packaging Pre & Post install mechanism that I have for Debian brought into RPMs?

It’s not a big deal to bring into the spec and start forum testing it.

I actually thought this changes were already being applied to RPMs. This is what we were discussing in this thread, right?

I have been making small adjustments to Debian packaging.
Yesterday, I had to enhance the packaging to account for PCI tuner cards.

I can bring it all over now and have a forum test. I have no problem with that if you/others don’t mind having dev-built (unsigned) packages ?

Oh, ok I see. No worries, I can wait until the formal release.

I’m almost done with updating my working copy of the spec.
I can probably have the forum preview ready today – forest fires nowithstanding :wink:

EDIT: Using my test binaries (1.18.7)

[root@localhost output-all]# yum install ./plexmediaserver-1.18.7.2438-f342a5a43.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining ./plexmediaserver-1.18.7.2438-f342a5a43.x86_64.rpm: plexmediaserver-1.18.7.2438-f342a5a43.x86_64
Marking ./plexmediaserver-1.18.7.2438-f342a5a43.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package plexmediaserver.x86_64 0:1.18.7.2438-f342a5a43 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================
 Package                     Arch               Version                            Repository                                                 Size
===================================================================================================================================================
Installing:
 plexmediaserver             x86_64             1.18.7.2438-f342a5a43              /plexmediaserver-1.18.7.2438-f342a5a43.x86_64             286 M

Transaction Summary
===================================================================================================================================================
Install  1 Package

Total size: 286 M
Installed size: 286 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
PlexMediaServer install: Pre-installation Validation.
PlexMediaServer install: Pre-installation Validation complete.
  Installing : plexmediaserver-1.18.7.2438-f342a5a43.x86_64                                                                                    1/1 
PlexMediaServer install: 1.18.7.2438-f342a5a43 - Installation starting.
PlexMediaServer install: 
PlexMediaServer install: Now installing based on:
PlexMediaServer install:   Installation Type:   Update
PlexMediaServer install:   Process Control:     systemd
PlexMediaServer install:   Plex User:           plex
PlexMediaServer install:   Plex Group:          plex
PlexMediaServer install:   Video Group:         video
PlexMediaServer install:   Metadata Dir:        /var/lib/plexmediaserver/Library/Application Support
PlexMediaServer install:   Temp Directory:      /tmp 
PlexMediaServer install:   Lang Encoding:       en_US.UTF-8
PlexMediaServer install:   Config file used:    /etc/systemd/system/plexmediaserver.service.d/stuff.conf
PlexMediaServer install:   Transcoding HW:      Found
PlexMediaServer install: 
PlexMediaServer install: Completing final configuration.
Created symlink from /etc/systemd/system/multi-user.target.wants/plexmediaserver.service to /usr/lib/systemd/system/plexmediaserver.service.
PlexMediaServer install: Starting Plex Media Server.
PlexMediaServer install: 1.18.7.2438-f342a5a43 - Installation successful.  Errors: 0, Warnings: 0
  Verifying  : plexmediaserver-1.18.7.2438-f342a5a43.x86_64                                                                                    1/1 

Installed:
  plexmediaserver.x86_64 0:1.18.7.2438-f342a5a43                                                                                                   

Complete!
[root@localhost output-all]# 

@oht0Ko5i

If you’re in the mood, PMS 1.19.4 with new RPM packaging.

Looks ok in Centos 7 VM.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.