#!/bin/sh
# DEF-43287: After upgrading the rustbolit binary, kick the
# aibolit-resident service so the new binary takes effect immediately.
# Without this, the old binary stays in memory until the next idle
# stay-alive exit (5 minutes by default) or a reboot, leaving
# customers running the previous version for hours after `apt upgrade`.
#
# Only the service needs restarting — the socket is a kernel listener
# bound to a path; upgrading the rustbolit binary doesn't change it,
# and restarting the socket would propagate a stop to the service via
# `Requires=aibolit-resident.socket`, causing a double restart (or in
# pathological cases an orphaned inactive service).
#
# try-restart is a no-op when the unit isn't loaded, so we ignore
# errors — the aibolit-resident.{service,socket} units are shipped by
# the separate `ai-bolit` package and may not be present on every host.
set -e

case "$1" in
    configure)
        if command -v systemctl >/dev/null 2>&1; then
            systemctl try-restart aibolit-resident.service >/dev/null 2>&1 || true
        fi
        ;;
    abort-upgrade|abort-remove|abort-deconfigure)
        ;;
    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
        ;;
esac



exit 0
