trap EXIT is how a script cleans up after itself

A script that creates a temporary directory, a lock file or a maintenance flag has to remove it on every path out — including the ones it did not anticipate.

#!/usr/bin/env bash
set -euo pipefail

tmp=$(mktemp -d)
touch /var/www/app/storage/framework/down

cleanup() {
    rm -rf "$tmp"
    rm -f /var/www/app/storage/framework/down
}
trap cleanup EXIT

trap ... EXIT fires on normal exit, on an error under set -e, and on most signals, which covers everything except kill -9. Registering it immediately after creating the resource rather than at the top of the script is what makes it correct — a trap registered before mktemp runs against an unset variable. The maintenance flag case is the one worth having: a deploy that fails halfway and leaves the site in maintenance mode is a longer outage than the failure itself.