diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bdbbf0e572..51ed203988 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 diff --git a/packaging/deb/scripts/BUILD b/packaging/deb/scripts/BUILD index 31c2d6bc4c..6c95f66377 100644 --- a/packaging/deb/scripts/BUILD +++ b/packaging/deb/scripts/BUILD @@ -1 +1 @@ -shell_sources(skip_shellcheck=True) +shell_sources() diff --git a/packaging/deb/scripts/post-install.sh b/packaging/deb/scripts/post-install.sh index 43b9cad25d..539fe027ef 100644 --- a/packaging/deb/scripts/post-install.sh +++ b/packaging/deb/scripts/post-install.sh @@ -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 diff --git a/packaging/deb/scripts/post-remove.sh b/packaging/deb/scripts/post-remove.sh index 0347af5c40..53b1ca695a 100644 --- a/packaging/deb/scripts/post-remove.sh +++ b/packaging/deb/scripts/post-remove.sh @@ -24,6 +24,47 @@ set -e # on upgrade failed (after or 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 || : @@ -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 diff --git a/packaging/deb/scripts/pre-install.sh b/packaging/deb/scripts/pre-install.sh index a19994f80a..9e56546be3 100644 --- a/packaging/deb/scripts/pre-install.sh +++ b/packaging/deb/scripts/pre-install.sh @@ -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) || @@ -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 diff --git a/packaging/deb/scripts/pre-remove.sh b/packaging/deb/scripts/pre-remove.sh index fc644fd39c..6ddef75a52 100644 --- a/packaging/deb/scripts/pre-remove.sh +++ b/packaging/deb/scripts/pre-remove.sh @@ -17,3 +17,43 @@ set -e # failed-upgrade # on upgrade failed (after 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 diff --git a/packaging/rpm/scripts/BUILD b/packaging/rpm/scripts/BUILD index 31c2d6bc4c..6c95f66377 100644 --- a/packaging/rpm/scripts/BUILD +++ b/packaging/rpm/scripts/BUILD @@ -1 +1 @@ -shell_sources(skip_shellcheck=True) +shell_sources() diff --git a/packaging/rpm/scripts/post-install.sh b/packaging/rpm/scripts/post-install.sh index 362ff56b6d..264dd0616f 100644 --- a/packaging/rpm/scripts/post-install.sh +++ b/packaging/rpm/scripts/post-install.sh @@ -1,3 +1,4 @@ +#!/bin/bash set -e # This %post scriptlet gets one argument, $1, the number of packages of @@ -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 || : + +# 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 diff --git a/packaging/rpm/scripts/post-remove.sh b/packaging/rpm/scripts/post-remove.sh index f2cc17a977..cc22a069c7 100644 --- a/packaging/rpm/scripts/post-remove.sh +++ b/packaging/rpm/scripts/post-remove.sh @@ -1,3 +1,4 @@ +#!/bin/bash set -e # This %postun scriptlet gets one argument, $1, the number of packages of @@ -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 diff --git a/packaging/rpm/scripts/pre-install.sh b/packaging/rpm/scripts/pre-install.sh index 36d7325661..81507169b6 100644 --- a/packaging/rpm/scripts/pre-install.sh +++ b/packaging/rpm/scripts/pre-install.sh @@ -1,3 +1,4 @@ +#!/bin/bash set -e # This %pre scriptlet gets one argument, $1, the number of packages of @@ -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} +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) || diff --git a/packaging/rpm/scripts/pre-remove.sh b/packaging/rpm/scripts/pre-remove.sh index 6f65230cca..a01900762b 100644 --- a/packaging/rpm/scripts/pre-remove.sh +++ b/packaging/rpm/scripts/pre-remove.sh @@ -1,3 +1,4 @@ +#!/bin/bash set -e # This %preun scriptlet gets one argument, $1, the number of packages of @@ -6,7 +7,34 @@ set -e # * on uninstall: $1 = 0 # https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax -# from %preun in st2-packages.git/packages/st2/rpm/st2.spec -%service_preun st2actionrunner %{worker_name} st2api st2stream st2auth st2notifier st2workflowengine -%service_preun st2rulesengine st2timersengine st2sensorcontainer st2garbagecollector -%service_preun 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_preun +# 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 0 ]; then + # Package removal, not upgrade + if [ -x "/usr/lib/systemd/systemd-update-helper" ]; then # EL 9 + # shellcheck disable=SC2086 + /usr/lib/systemd/systemd-update-helper remove-system-units ${_ST2_SERVICES} || : + else # EL 8 + # shellcheck disable=SC2086 + systemctl --no-reload disable --now ${_ST2_SERVICES} &>/dev/null || : + fi +fi