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
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:
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.
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.
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)