What happened?
When upgrading rpm packages, the scripts generated by nfpm do not do the right thing for upgrades. For instance, look at the pre-install script generated by nfpm, (using rpm -qp --scripts <rpmfile>
) it looks like:
preinstall scriptlet (using /bin/sh):
#!/bin/bash
echo "Creating user and group..."
GROUPNAME="tyk"
USERNAME="tyk"
getent group "$GROUPNAME" >/dev/null || groupadd -r "$GROUPNAME"
getent passwd "$USERNAME" >/dev/null || useradd -r -g "$GROUPNAME" -M -s /sbin/nologin -c "Tyk service user" "$USERNAME"
While the package generated by fpm looks like:
preinstall scriptlet (using /bin/sh):
upgrade() {
:
#!/bin/bash
echo "Removing init scripts..."
SYSTEMD="/lib/systemd/system"
UPSTART="/etc/init"
SYSV1="/etc/init.d"
SYSV2="/etc/rc.d/init.d/"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -f "/lib/systemd/system/tyk-dashboard.service" ]; then
echo "Found Systemd"
echo "Stopping the service"
systemctl stop tyk-dashboard.service
echo "Removing the service"
rm /lib/systemd/system/tyk-dashboard.service
systemctl --system daemon-reload
fi
if [ -f "/etc/init/tyk-dashboard.conf" ]; then
echo "Found upstart"
echo "Stopping the service"
stop tyk-dashboard
echo "Removing the service"
rm /etc/init/tyk-dashboard.conf
fi
if [ -f "/etc/init.d/tyk-dashboard" ]; then
echo "Found Sysv1"
/etc/init.d/tyk-dashboard stop
rm /etc/init.d/tyk-dashboard
fi
if [ -f "/etc/rc.d/init.d/tyk-dashboard" ]; then
echo "Found Sysv2"
echo "Stopping the service"
/etc/rc.d/init.d/tyk-dashboard stop
echo "Removing the service"
rm /etc/rc.d/init.d/tyk-dashboard
fi
}
_install() {
:
#!/bin/bash
echo "Creating user and group..."
GROUPNAME="tyk"
USERNAME="tyk"
getent group "$GROUPNAME" >/dev/null || groupadd -r "$GROUPNAME"
getent passwd "$USERNAME" >/dev/null || useradd -r -g "$GROUPNAME" -M -s /sbin/nologin -c "Tyk service user" "$USERNAME"
}
if [ "${1}" -eq 1 ]
then
# "before install" goes here
_install
elif [ "${1}" -gt 1 ]
then
# "before upgrade" goes here
upgrade
fi
The fpm version does the right thing imho.
How can we reproduce this?
Using https://packagecloud.io/tyk/tyk-gateway-unstable,
# yum install tyk-gateway-3.0.5~rc2
# yum install tyk-gateway-3.0.7~rc23
You will see that the systemd service file is removed at the end of the upgrade as it is in the postuninstall trigger of the old package.
As per the spec, the postuninstall trigger of the old package runs after the postinstall trigger of the new package. This is a little confusing but the fpm generated trigger scripts use $1
to figure out the right situation.
I can't be the first to encounter this problem but I'm not sure if I am doing something wrong.
You can see the goreleaser config at https://github.com/TykTechnologies/tyk/blob/master/.goreleaser.yml#L263-L266
goreleaser version
goreleaser version 0.155.0
GoReleaser Check
- [X] goreleaser check shows no errors
Search
- [X] I did search for other open and closed issues before opening this.
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Additional context
I have also checked the scripts with GoReleaser version found: v0.169.0 and the scripts are the generated without reference to $1.
We also have a goreleaser license from gumroad, if that makes a difference.