Skip to content

Commit 6535ff5

Browse files
authoredMar 19, 2025··
Packaging: expand DEBHELPER in deb maintainer scripts and macros in rpm scriptlets (#6319)
2 parents df55287 + 775b902 commit 6535ff5

11 files changed

+273
-53
lines changed
 

‎CHANGELOG.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Added
7979
to pants' use of PEX lockfiles. This is not a user-facing addition.
8080
#6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240 #6241 #6244 #6251 #6253
8181
#6254 #6258 #6259 #6260 #6269 #6275 #6279 #6278 #6282 #6283 #6273 #6287 #6306 #6307
82-
#6311 #6314 #6315 #6317
82+
#6311 #6314 #6315 #6317 #6319
8383
Contributed by @cognifloyd
8484
* Build of ST2 EL9 packages #6153
8585
Contributed by @amanda11

‎packaging/deb/scripts/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
shell_sources(skip_shellcheck=True)
1+
shell_sources()

‎packaging/deb/scripts/post-install.sh

+63-11
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,74 @@ set -e
2929
# https://www.mankier.com/5/deb-triggers
3030
# https://stackoverflow.com/questions/15276535/dpkg-how-to-use-trigger
3131

32+
# This must include ".service" to satisfy deb-systemd-{helper,invoke}
33+
_ST2_SERVICES="
34+
st2actionrunner.service
35+
st2api.service
36+
st2auth.service
37+
st2garbagecollector.service
38+
st2notifier.service
39+
st2rulesengine.service
40+
st2scheduler.service
41+
st2sensorcontainer.service
42+
st2stream.service
43+
st2timersengine.service
44+
st2workflowengine.service
45+
"
46+
47+
# Native .deb maintainer scripts are injected with debhelper snippets.
48+
# We are using nfpm, so we inline those snippets here.
49+
# https://github.com/Debian/debhelper/blob/debian/12.10/dh_systemd_start
50+
# https://github.com/Debian/debhelper/blob/debian/12.10/dh_systemd_enable
51+
# https://github.com/Debian/debhelper/blob/debian/12.10/autoscripts/postinst-systemd-enable
52+
# https://github.com/Debian/debhelper/blob/debian/12.10/autoscripts/postinst-systemd-restart
53+
54+
systemd_enable() {
55+
# This will only remove masks created by d-s-h on package removal.
56+
deb-systemd-helper unmask "${1}" >/dev/null || true
57+
58+
# was-enabled defaults to true, so new installations run enable.
59+
if deb-systemd-helper --quiet was-enabled "${1}"; then
60+
# Enables the unit on first installation, creates new
61+
# symlinks on upgrades if the unit file has changed.
62+
deb-systemd-helper enable "${1}" >/dev/null || true
63+
else
64+
# Update the statefile to add new symlinks (if any), which need to be
65+
# cleaned up on purge. Also remove old symlinks.
66+
deb-systemd-helper update-state "${1}" >/dev/null || true
67+
fi
68+
}
69+
70+
if [ -n "$2" ]; then
71+
_dh_action=restart
72+
else
73+
_dh_action=start
74+
fi
75+
76+
systemd_enable_and_restart() {
77+
for service in "${@}"; do
78+
systemd_enable "${service}"
79+
done
80+
if [ -d /run/systemd/system ]; then
81+
systemctl --system daemon-reload >/dev/null || true
82+
deb-systemd-invoke $_dh_action "${@}" >/dev/null || true
83+
fi
84+
}
85+
3286
case "$1" in
3387
configure)
34-
# make sure that our socket generators run
35-
systemctl daemon-reload >/dev/null 2>&1 || true
88+
# shellcheck disable=SC2086
89+
systemd_enable_and_restart ${_ST2_SERVICES}
90+
;;
91+
abort-upgrade | abort-remove | abort-deconfigure)
92+
# dh_systemd_* runs this for all actions, not just configure
93+
# shellcheck disable=SC2086
94+
systemd_enable_and_restart ${_ST2_SERVICES}
3695
;;
37-
abort-upgrade | abort-remove | abort-deconfigure) ;;
38-
3996
*)
40-
echo "postinst called with unknown argument \`$1'" >&2
41-
exit 1
97+
# echo "postinst called with unknown argument \`$1'" >&2
98+
# exit 1
4299
;;
43100
esac
44101

45-
# dh_installdeb will replace this with shell code automatically
46-
# generated by other debhelper scripts.
47-
48-
#DEBHELPER#
49-
50102
exit 0

‎packaging/deb/scripts/post-remove.sh

+52-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,47 @@ set -e
2424
# on upgrade failed (after <new-preinst> or <old-postrm> failed)
2525
# https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html
2626

27+
# This must include ".service" to satisfy deb-systemd-helper
28+
_ST2_SERVICES="
29+
st2actionrunner.service
30+
st2api.service
31+
st2auth.service
32+
st2garbagecollector.service
33+
st2notifier.service
34+
st2rulesengine.service
35+
st2scheduler.service
36+
st2sensorcontainer.service
37+
st2stream.service
38+
st2timersengine.service
39+
st2workflowengine.service
40+
"
41+
42+
# Native .deb maintainer scripts are injected with debhelper snippets.
43+
# We are using nfpm, so we inline those snippets here.
44+
# https://github.com/Debian/debhelper/blob/debian/12.10/dh_systemd_start
45+
# https://github.com/Debian/debhelper/blob/debian/12.10/dh_systemd_enable
46+
# https://github.com/Debian/debhelper/blob/debian/12.10/autoscripts/postrm-systemd
47+
# https://github.com/Debian/debhelper/blob/debian/12.10/autoscripts/postrm-systemd-reload-only
48+
49+
systemd_remove() {
50+
if [ -x "/usr/bin/deb-systemd-helper" ]; then
51+
deb-systemd-helper mask "${@}" >/dev/null || true
52+
fi
53+
}
54+
55+
systemd_purge() {
56+
if [ -x "/usr/bin/deb-systemd-helper" ]; then
57+
deb-systemd-helper purge "${@}" >/dev/null || true
58+
deb-systemd-helper unmask "${@}" >/dev/null || true
59+
fi
60+
}
61+
62+
systemd_reload() {
63+
if [ -d "/run/systemd/system" ]; then
64+
systemctl --system daemon-reload >/dev/null || true
65+
fi
66+
}
67+
2768
purge_files() {
2869
# This -pkgsaved.disabled file might be left over from old (buggy) deb packages
2970
rm -f /etc/logrotate.d/st2-pkgsaved.disabled 1>/dev/null 2>&1 || :
@@ -36,19 +77,22 @@ purge_files() {
3677
}
3778

3879
case "$1" in
80+
remove)
81+
# shellcheck disable=SC2086
82+
systemd_remove ${_ST2_SERVICES}
83+
systemd_reload
84+
;;
3985
purge)
86+
# shellcheck disable=SC2086
87+
systemd_purge ${_ST2_SERVICES}
88+
systemd_reload
4089
purge_files
4190
;;
42-
remove | upgrade | failed-upgrade | abort-install | abort-upgrade | disappear) ;;
91+
upgrade | failed-upgrade | abort-install | abort-upgrade | disappear) ;;
4392
*)
44-
echo "postrm called with unknown argument \`$1'" >&2
45-
exit 1
93+
# echo "postrm called with unknown argument \`$1'" >&2
94+
# exit 1
4695
;;
4796
esac
4897

49-
# dh_installdeb will replace this with shell code automatically
50-
# generated by other debhelper scripts.
51-
52-
#DEBHELPER#
53-
5498
exit 0

‎packaging/deb/scripts/pre-install.sh

+4-12
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ PACKS_GROUP=st2packs
2020
SYS_USER=stanley
2121
ST2_USER=st2
2222

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

4141
case "$1" in
42-
install)
43-
create_users
44-
;;
45-
upgrade)
42+
install | upgrade)
4643
create_users
4744
;;
4845
abort-upgrade) ;;
4946
*)
50-
echo "preinst called with unknown argument \`$1'" >&2
51-
exit 1
47+
# echo "preinst called with unknown argument \`$1'" >&2
48+
# exit 1
5249
;;
5350
esac
5451

55-
# dh_installdeb will replace this with shell code automatically
56-
# generated by other debhelper scripts.
57-
58-
#DEBHELPER#
59-
6052
exit 0

‎packaging/deb/scripts/pre-remove.sh

+40
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,43 @@ set -e
1717
# <new-prerm> failed-upgrade <old-version> <new-version>
1818
# on upgrade failed (after <old-prerm> failed)
1919
# https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html
20+
21+
# This must include ".service" to satisfy deb-systemd-invoke
22+
_ST2_SERVICES="
23+
st2actionrunner.service
24+
st2api.service
25+
st2auth.service
26+
st2garbagecollector.service
27+
st2notifier.service
28+
st2rulesengine.service
29+
st2scheduler.service
30+
st2sensorcontainer.service
31+
st2stream.service
32+
st2timersengine.service
33+
st2workflowengine.service
34+
"
35+
36+
# Native .deb maintainer scripts are injected with debhelper snippets.
37+
# We are using nfpm, so we inline those snippets here.
38+
# https://github.com/Debian/debhelper/blob/debian/12.10/dh_systemd_start
39+
# https://github.com/Debian/debhelper/blob/debian/12.10/autoscripts/prerm-systemd-restart
40+
41+
systemd_stop() {
42+
if [ -d "/run/systemd/system" ]; then
43+
deb-systemd-invoke stop "${@}" >/dev/null || true
44+
fi
45+
}
46+
47+
case "$1" in
48+
remove)
49+
# shellcheck disable=SC2086
50+
systemd_stop ${_ST2_SERVICES}
51+
;;
52+
upgrade | deconfigure | failed-upgrade) ;;
53+
*)
54+
# echo "prerm called with unknown argument \`$1'" >&2
55+
# exit 1
56+
;;
57+
esac
58+
59+
exit 0

‎packaging/rpm/scripts/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
shell_sources(skip_shellcheck=True)
1+
shell_sources()

‎packaging/rpm/scripts/post-install.sh

+41-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
set -e
23

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

9-
# from %post in st2-packages.git/packages/st2/rpm/st2.spec
10-
%service_post st2actionrunner st2api st2stream st2auth st2notifier st2workflowengine
11-
%service_post st2rulesengine st2timersengine st2sensorcontainer st2garbagecollector
12-
%service_post st2scheduler
10+
_ST2_SERVICES="
11+
st2actionrunner
12+
st2api
13+
st2auth
14+
st2garbagecollector
15+
st2notifier
16+
st2rulesengine
17+
st2scheduler
18+
st2sensorcontainer
19+
st2stream
20+
st2timersengine
21+
st2workflowengine
22+
"
1323

14-
# make sure that our socket generators run
15-
systemctl daemon-reload >/dev/null 2>&1 || true
24+
# Native .rpm specs use macros that get expanded into shell snippets.
25+
# We are using nfpm, so we inline the macro expansion here.
26+
# %systemd_post
27+
# EL8: https://github.com/systemd/systemd/blob/v239/src/core/macros.systemd.in
28+
# EL9: https://github.com/systemd/systemd/blob/v252/src/rpm/macros.systemd.in
29+
30+
if [ "$1" -eq 1 ]; then
31+
# Initial installation
32+
if [ -x "/usr/lib/systemd/systemd-update-helper" ]; then # EL 9
33+
# shellcheck disable=SC2086
34+
/usr/lib/systemd/systemd-update-helper install-system-units ${_ST2_SERVICES} || :
35+
else # EL 8
36+
# shellcheck disable=SC2086
37+
systemctl --no-reload preset ${_ST2_SERVICES} &>/dev/null || :
38+
fi
39+
fi
40+
41+
# shellcheck disable=SC2086
42+
# TODO: Maybe remove this as 'preset' (on install above) enables units by default
43+
systemctl --no-reload enable ${_ST2_SERVICES} &>/dev/null || :
44+
45+
# make sure that our socket/unit generators run
46+
if [ -x "/usr/lib/systemd/systemd-update-helper" ]; then # EL 9
47+
/usr/lib/systemd/systemd-update-helper system-reload || :
48+
else # EL 8
49+
systemctl daemon-reload &>/dev/null || :
50+
fi

‎packaging/rpm/scripts/post-remove.sh

+33-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
set -e
23

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

9-
# from %postun in st2-packages.git/packages/st2/rpm/st2.spec
10-
%service_postun st2actionrunner %{worker_name} st2api st2stream st2auth st2notifier st2workflowengine
11-
%service_postun st2rulesengine st2timersengine st2sensorcontainer st2garbagecollector
12-
%service_postun st2scheduler
10+
_ST2_SERVICES="
11+
st2actionrunner
12+
st2actionrunner@
13+
st2api
14+
st2auth
15+
st2garbagecollector
16+
st2notifier
17+
st2rulesengine
18+
st2scheduler
19+
st2sensorcontainer
20+
st2stream
21+
st2timersengine
22+
st2workflowengine
23+
"
24+
25+
# Native .rpm specs use macros that get expanded into shell snippets.
26+
# We are using nfpm, so we inline the macro expansion here.
27+
# %systemd_postun_with_restart
28+
# EL8: https://github.com/systemd/systemd/blob/v239/src/core/macros.systemd.in
29+
# EL9: https://github.com/systemd/systemd/blob/v252/src/rpm/macros.systemd.in
30+
31+
if [ "$1" -ge 1 ]; then
32+
# Package upgrade, not uninstall
33+
if [ -x "/usr/lib/systemd/systemd-update-helper" ]; then # EL 9
34+
# shellcheck disable=SC2086
35+
/usr/lib/systemd/systemd-update-helper mark-restart-system-units ${_ST2_SERVICES} || :
36+
else # EL 8
37+
# shellcheck disable=SC2086
38+
systemctl try-restart ${_ST2_SERVICES} &>/dev/null || :
39+
fi
40+
fi
1341

1442
# Remove st2 logrotate config, since there's no analog of apt-get purge available
15-
if [ $1 -eq 0 ]; then
43+
if [ "$1" -eq 0 ]; then
1644
rm -f /etc/logrotate.d/st2
1745
fi

‎packaging/rpm/scripts/pre-install.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
set -e
23

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

9-
PACKS_GROUP=%{packs_group}
10-
SYS_USER=%{stanley_user}
11-
ST2_USER=%{svc_user}
10+
PACKS_GROUP=st2packs
11+
SYS_USER=stanley
12+
ST2_USER=st2
1213

13-
## Create stackstorm users and groups (differs from debian)
14+
## Create stackstorm users and groups (adduser differs from debian)
1415
create_users() {
1516
# create st2 user (services user)
1617
(id $ST2_USER 1>/dev/null 2>&1) ||

‎packaging/rpm/scripts/pre-remove.sh

+32-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
set -e
23

34
# This %preun scriptlet gets one argument, $1, the number of packages of
@@ -6,7 +7,34 @@ set -e
67
# * on uninstall: $1 = 0
78
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax
89

9-
# from %preun in st2-packages.git/packages/st2/rpm/st2.spec
10-
%service_preun st2actionrunner %{worker_name} st2api st2stream st2auth st2notifier st2workflowengine
11-
%service_preun st2rulesengine st2timersengine st2sensorcontainer st2garbagecollector
12-
%service_preun st2scheduler
10+
_ST2_SERVICES="
11+
st2actionrunner
12+
st2actionrunner@
13+
st2api
14+
st2auth
15+
st2garbagecollector
16+
st2notifier
17+
st2rulesengine
18+
st2scheduler
19+
st2sensorcontainer
20+
st2stream
21+
st2timersengine
22+
st2workflowengine
23+
"
24+
25+
# Native .rpm specs use macros that get expanded into shell snippets.
26+
# We are using nfpm, so we inline the macro expansion here.
27+
# %systemd_preun
28+
# EL8: https://github.com/systemd/systemd/blob/v239/src/core/macros.systemd.in
29+
# EL9: https://github.com/systemd/systemd/blob/v252/src/rpm/macros.systemd.in
30+
31+
if [ "$1" -eq 0 ]; then
32+
# Package removal, not upgrade
33+
if [ -x "/usr/lib/systemd/systemd-update-helper" ]; then # EL 9
34+
# shellcheck disable=SC2086
35+
/usr/lib/systemd/systemd-update-helper remove-system-units ${_ST2_SERVICES} || :
36+
else # EL 8
37+
# shellcheck disable=SC2086
38+
systemctl --no-reload disable --now ${_ST2_SERVICES} &>/dev/null || :
39+
fi
40+
fi

0 commit comments

Comments
 (0)
Please sign in to comment.