@@ -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+
3286case " $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 ;;
43100esac
44101
45- # dh_installdeb will replace this with shell code automatically
46- # generated by other debhelper scripts.
47-
48- # DEBHELPER#
49-
50102exit 0
0 commit comments