if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ]; then
    if [ -x "/usr/bin/svctl" ]; then
        # Enable a unit exactly once: when it did not exist before this package
        # version (recorded by preinst). An admin's later "svctl disable" is
        # respected on upgrades, and the check does not depend on the state of
        # the s6-rc databases, which other maintainer scripts in the same dpkg
        # run may already have recompiled with our unit in it.
        existing="/var/lib/dh-s6/#PACKAGE#.existing"
        s6toenable=""
        for unit in #UNITFILES#; do
            if [ -f "$existing" ] && grep -qx "$unit" "$existing"; then
                continue
            fi
            s6toenable="$s6toenable $unit"
        done
        rm -f "$existing"
        # compile first (svctl enable resolves units against compiled-work),
        # then enable the new units and switch the live database
        svctl compile || true
        if [ -n "$s6toenable" ]; then
            svctl enable $s6toenable || true
        fi
        svctl update || true
    fi
fi
