diff --git a/scripts/debian/postinst.in b/scripts/debian/postinst.in index 75d600aa..d58d54c1 100755 --- a/scripts/debian/postinst.in +++ b/scripts/debian/postinst.in @@ -41,3 +41,34 @@ case "$1" in fi ;; esac + +# Based off what debhelper dh_systemd_enable/13.3.4 would have added +# ref: https://www.debian.org/doc/manuals/debmake-doc/ch05.en.html#debhelper + +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + # This will only remove masks created by d-s-h on package removal. + deb-systemd-helper unmask 'falco.service' >/dev/null || true + + # was-enabled defaults to true, so new installations run enable. + if deb-systemd-helper --quiet was-enabled 'falco.service'; then + # Enables the unit on first installation, creates new + # symlinks on upgrades if the unit file has changed. + deb-systemd-helper enable 'falco.service' >/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 'falco.service' >/dev/null || true + fi +fi + +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + if [ -d /run/systemd/system ]; then + systemctl --system daemon-reload >/dev/null || true + if [ -n "$2" ]; then + _dh_action=restart + else + _dh_action=start + fi + deb-systemd-invoke $_dh_action 'falco.service' >/dev/null || true + fi +fi diff --git a/scripts/debian/postrm.in b/scripts/debian/postrm.in index 0181a664..8134d806 100755 --- a/scripts/debian/postrm.in +++ b/scripts/debian/postrm.in @@ -15,3 +15,25 @@ # See the License for the specific language governing permissions and # limitations under the License. # + +# Based off what debhelper dh_systemd_enable/13.3.4 would have added +# ref: https://www.debian.org/doc/manuals/debmake-doc/ch05.en.html#debhelper + +set -e + +if [ -d /run/systemd/system ] && [ "$1" = remove ]; then + systemctl --system daemon-reload >/dev/null || true +fi + +if [ "$1" = "remove" ]; then + if [ -x "/usr/bin/deb-systemd-helper" ]; then + deb-systemd-helper mask 'falco.service' >/dev/null || true + fi +fi + +if [ "$1" = "purge" ]; then + if [ -x "/usr/bin/deb-systemd-helper" ]; then + deb-systemd-helper purge 'falco.service' >/dev/null || true + deb-systemd-helper unmask 'falco.service' >/dev/null || true + fi +fi diff --git a/scripts/debian/prerm.in b/scripts/debian/prerm.in index f434ecb2..1a72292e 100755 --- a/scripts/debian/prerm.in +++ b/scripts/debian/prerm.in @@ -17,6 +17,14 @@ # set -e +# Based off what debhelper dh_systemd_enable/13.3.4 would have added +# ref: https://www.debian.org/doc/manuals/debmake-doc/ch05.en.html#debhelper +# Currently running falco service uses the driver, so stop it before driver cleanup + +if [ -d /run/systemd/system ] && [ "$1" = remove ]; then + deb-systemd-invoke stop 'falco.service' >/dev/null || true +fi + case "$1" in remove|upgrade|deconfigure) /usr/bin/falco-driver-loader --clean