Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Added
to pants' use of PEX lockfiles. This is not a user-facing addition.
#6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240 #6241 #6244 #6251 #6253
#6254 #6258 #6259 #6260 #6269 #6275 #6279 #6278 #6282 #6283 #6273 #6287 #6306 #6307
#6311 #6314 #6315 #6317
#6311 #6314 #6315 #6317 #6319
Contributed by @cognifloyd
* Build of ST2 EL9 packages #6153
Contributed by @amanda11
Expand Down
2 changes: 1 addition & 1 deletion packaging/deb/scripts/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1 @@
shell_sources(skip_shellcheck=True)
shell_sources()
74 changes: 63 additions & 11 deletions packaging/deb/scripts/post-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,74 @@ set -e
# https://www.mankier.com/5/deb-triggers
# https://stackoverflow.com/questions/15276535/dpkg-how-to-use-trigger

# This must include ".service" to satisfy deb-systemd-{helper,invoke}
_ST2_SERVICES="
st2actionrunner.service
st2api.service
st2auth.service
st2garbagecollector.service
st2notifier.service
st2rulesengine.service
st2scheduler.service
st2sensorcontainer.service
st2stream.service
st2timersengine.service
st2workflowengine.service
"

# Native .deb maintainer scripts are injected with debhelper snippets.
# We are using nfpm, so we inline those snippets here.
# https://github.com/Debian/debhelper/blob/debian/12.10/dh_systemd_start
# https://github.com/Debian/debhelper/blob/debian/12.10/dh_systemd_enable
# https://github.com/Debian/debhelper/blob/debian/12.10/autoscripts/postinst-systemd-enable
# https://github.com/Debian/debhelper/blob/debian/12.10/autoscripts/postinst-systemd-restart

systemd_enable() {
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask "${1}" >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled "${1}"; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper enable "${1}" >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper update-state "${1}" >/dev/null || true
fi
}

if [ -n "$2" ]; then
_dh_action=restart
else
_dh_action=start
fi

systemd_enable_and_restart() {
for service in "${@}"; do
systemd_enable "${service}"
done
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
deb-systemd-invoke $_dh_action "${@}" >/dev/null || true
fi
}

case "$1" in
configure)
# make sure that our socket generators run
systemctl daemon-reload >/dev/null 2>&1 || true
# shellcheck disable=SC2086
systemd_enable_and_restart ${_ST2_SERVICES}
;;
abort-upgrade | abort-remove | abort-deconfigure)
# dh_systemd_* runs this for all actions, not just configure
# shellcheck disable=SC2086
systemd_enable_and_restart ${_ST2_SERVICES}
;;
abort-upgrade | abort-remove | abort-deconfigure) ;;

*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
# echo "postinst called with unknown argument \`$1'" >&2
# exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
60 changes: 52 additions & 8 deletions packaging/deb/scripts/post-remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,47 @@ set -e
# on upgrade failed (after <new-preinst> or <old-postrm> failed)
# https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html

# This must include ".service" to satisfy deb-systemd-helper
_ST2_SERVICES="
st2actionrunner.service
st2api.service
st2auth.service
st2garbagecollector.service
st2notifier.service
st2rulesengine.service
st2scheduler.service
st2sensorcontainer.service
st2stream.service
st2timersengine.service
st2workflowengine.service
"

# Native .deb maintainer scripts are injected with debhelper snippets.
# We are using nfpm, so we inline those snippets here.
# https://github.com/Debian/debhelper/blob/debian/12.10/dh_systemd_start
# https://github.com/Debian/debhelper/blob/debian/12.10/dh_systemd_enable
# https://github.com/Debian/debhelper/blob/debian/12.10/autoscripts/postrm-systemd
# https://github.com/Debian/debhelper/blob/debian/12.10/autoscripts/postrm-systemd-reload-only

systemd_remove() {
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper mask "${@}" >/dev/null || true
fi
}

systemd_purge() {
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper purge "${@}" >/dev/null || true
deb-systemd-helper unmask "${@}" >/dev/null || true
fi
}

systemd_reload() {
if [ -d "/run/systemd/system" ]; then
systemctl --system daemon-reload >/dev/null || true
fi
}

purge_files() {
# This -pkgsaved.disabled file might be left over from old (buggy) deb packages
rm -f /etc/logrotate.d/st2-pkgsaved.disabled 1>/dev/null 2>&1 || :
Expand All @@ -36,19 +77,22 @@ purge_files() {
}

case "$1" in
remove)
# shellcheck disable=SC2086
systemd_remove ${_ST2_SERVICES}
systemd_reload
;;
purge)
# shellcheck disable=SC2086
systemd_purge ${_ST2_SERVICES}
systemd_reload
purge_files
;;
remove | upgrade | failed-upgrade | abort-install | abort-upgrade | disappear) ;;
upgrade | failed-upgrade | abort-install | abort-upgrade | disappear) ;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
# echo "postrm called with unknown argument \`$1'" >&2
# exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
16 changes: 4 additions & 12 deletions packaging/deb/scripts/pre-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PACKS_GROUP=st2packs
SYS_USER=stanley
ST2_USER=st2

## Create stackstorm users and groups
## Create stackstorm users and groups (adduser differs from EL)
create_users() {
# create st2 user (services user)
(id $ST2_USER 1>/dev/null 2>&1) ||
Expand All @@ -39,22 +39,14 @@ create_users() {
}

case "$1" in
install)
create_users
;;
upgrade)
install | upgrade)
create_users
;;
abort-upgrade) ;;
*)
echo "preinst called with unknown argument \`$1'" >&2
exit 1
# echo "preinst called with unknown argument \`$1'" >&2
# exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
40 changes: 40 additions & 0 deletions packaging/deb/scripts/pre-remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,43 @@ set -e
# <new-prerm> failed-upgrade <old-version> <new-version>
# on upgrade failed (after <old-prerm> failed)
# https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html

# This must include ".service" to satisfy deb-systemd-invoke
_ST2_SERVICES="
st2actionrunner.service
st2api.service
st2auth.service
st2garbagecollector.service
st2notifier.service
st2rulesengine.service
st2scheduler.service
st2sensorcontainer.service
st2stream.service
st2timersengine.service
st2workflowengine.service
"

# Native .deb maintainer scripts are injected with debhelper snippets.
# We are using nfpm, so we inline those snippets here.
# https://github.com/Debian/debhelper/blob/debian/12.10/dh_systemd_start
# https://github.com/Debian/debhelper/blob/debian/12.10/autoscripts/prerm-systemd-restart

systemd_stop() {
if [ -d "/run/systemd/system" ]; then
deb-systemd-invoke stop "${@}" >/dev/null || true
fi
}

case "$1" in
remove)
# shellcheck disable=SC2086
systemd_stop ${_ST2_SERVICES}
;;
upgrade | deconfigure | failed-upgrade) ;;
*)
# echo "prerm called with unknown argument \`$1'" >&2
# exit 1
;;
esac

exit 0
2 changes: 1 addition & 1 deletion packaging/rpm/scripts/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1 @@
shell_sources(skip_shellcheck=True)
shell_sources()
47 changes: 41 additions & 6 deletions packaging/rpm/scripts/post-install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
set -e

# This %post scriptlet gets one argument, $1, the number of packages of
Expand All @@ -6,10 +7,44 @@ set -e
# * on upgrade: $1 > 1
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax

# from %post in st2-packages.git/packages/st2/rpm/st2.spec
%service_post st2actionrunner st2api st2stream st2auth st2notifier st2workflowengine
%service_post st2rulesengine st2timersengine st2sensorcontainer st2garbagecollector
%service_post st2scheduler
_ST2_SERVICES="
st2actionrunner
st2api
st2auth
st2garbagecollector
st2notifier
st2rulesengine
st2scheduler
st2sensorcontainer
st2stream
st2timersengine
st2workflowengine
"

# make sure that our socket generators run
systemctl daemon-reload >/dev/null 2>&1 || true
# Native .rpm specs use macros that get expanded into shell snippets.
# We are using nfpm, so we inline the macro expansion here.
# %systemd_post
# EL8: https://github.com/systemd/systemd/blob/v239/src/core/macros.systemd.in
# EL9: https://github.com/systemd/systemd/blob/v252/src/rpm/macros.systemd.in

if [ "$1" -eq 1 ]; then
# Initial installation
if [ -x "/usr/lib/systemd/systemd-update-helper" ]; then # EL 9
# shellcheck disable=SC2086
/usr/lib/systemd/systemd-update-helper install-system-units ${_ST2_SERVICES} || :
else # EL 8
# shellcheck disable=SC2086
systemctl --no-reload preset ${_ST2_SERVICES} &>/dev/null || :
fi
fi

# shellcheck disable=SC2086
# TODO: Maybe remove this as 'preset' (on install above) enables units by default
systemctl --no-reload enable ${_ST2_SERVICES} &>/dev/null || :
Comment on lines +42 to +43
Copy link
Member Author

@cognifloyd cognifloyd Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I debated removing this now. I left a TODO for now. I think we should wait to remove it until we can actually test the built rpms.

This does not come from upstream. We defined it in st2-packages.git: https://github.com/StackStorm/st2-packages/blob/6c81c2e8e1c1e0f0ec0132c74c1f67730f6b9bf8/rpmspec/helpers.spec#L84-L90


# make sure that our socket/unit generators run
if [ -x "/usr/lib/systemd/systemd-update-helper" ]; then # EL 9
/usr/lib/systemd/systemd-update-helper system-reload || :
else # EL 8
systemctl daemon-reload &>/dev/null || :
fi
38 changes: 33 additions & 5 deletions packaging/rpm/scripts/post-remove.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
set -e

# This %postun scriptlet gets one argument, $1, the number of packages of
Expand All @@ -6,12 +7,39 @@ set -e
# * on uninstall: $1 = 0
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax

# from %postun in st2-packages.git/packages/st2/rpm/st2.spec
%service_postun st2actionrunner %{worker_name} st2api st2stream st2auth st2notifier st2workflowengine
%service_postun st2rulesengine st2timersengine st2sensorcontainer st2garbagecollector
%service_postun st2scheduler
_ST2_SERVICES="
st2actionrunner
st2actionrunner@
st2api
st2auth
st2garbagecollector
st2notifier
st2rulesengine
st2scheduler
st2sensorcontainer
st2stream
st2timersengine
st2workflowengine
"

# Native .rpm specs use macros that get expanded into shell snippets.
# We are using nfpm, so we inline the macro expansion here.
# %systemd_postun_with_restart
# EL8: https://github.com/systemd/systemd/blob/v239/src/core/macros.systemd.in
# EL9: https://github.com/systemd/systemd/blob/v252/src/rpm/macros.systemd.in

if [ "$1" -ge 1 ]; then
# Package upgrade, not uninstall
if [ -x "/usr/lib/systemd/systemd-update-helper" ]; then # EL 9
# shellcheck disable=SC2086
/usr/lib/systemd/systemd-update-helper mark-restart-system-units ${_ST2_SERVICES} || :
else # EL 8
# shellcheck disable=SC2086
systemctl try-restart ${_ST2_SERVICES} &>/dev/null || :
fi
fi

# Remove st2 logrotate config, since there's no analog of apt-get purge available
if [ $1 -eq 0 ]; then
if [ "$1" -eq 0 ]; then
rm -f /etc/logrotate.d/st2
fi
9 changes: 5 additions & 4 deletions packaging/rpm/scripts/pre-install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
set -e

# This %pre scriptlet gets one argument, $1, the number of packages of
Expand All @@ -6,11 +7,11 @@ set -e
# * on upgrade: $1 > 1
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax

PACKS_GROUP=%{packs_group}
SYS_USER=%{stanley_user}
ST2_USER=%{svc_user}
Comment on lines -9 to -11
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These macros were defined in st2.spec: https://github.com/StackStorm/st2-packages/blob/9974d04084b01cde9d11994f02abf46290c37fe3/packages/st2/rpm/st2.spec#L3-L5

The equivalent hard-coded values were already embedded in the deb maintainer scripts, so, this does not change anything. It only inlines the values for rpm.

PACKS_GROUP=st2packs
SYS_USER=stanley
ST2_USER=st2

## Create stackstorm users and groups (differs from debian)
## Create stackstorm users and groups (adduser differs from debian)
create_users() {
# create st2 user (services user)
(id $ST2_USER 1>/dev/null 2>&1) ||
Expand Down
Loading
Loading