Is It Possible to Run Macro at Shutdown/Restart?

Have you tried the sleep/wake triggers? Depending on how intrusive it is to restart Unifi Controller, this might be an option. I toggle a Kasa smart plug and Audio Hijack's run state at sleep and wake, without issue.

Also there's this.