What's the right way to execute a script before system shutdown (systemd)?

view full story

http://unix.stackexchange.com – I wrote a script that suspend all my virtualbox machines, and put a line in /etc/rc.local.shutdown, but it doesn't seem to work, su - XX -c /XX When I'm booted next time, virtualbox tells me the machine was Aborted, so the script wasn't executed. (Launching that script manually works for me) P.S I already enabled shutdown.target (HowTos)