Run script before other units stop on shutdown

by 2rs2ts   Last Updated September 21, 2018 02:01 AM

I need to run a script before a set of other services on my machine stop when shutting the machine down.

I have tried variations on the answer in this question but nothing works: How do I run a script before everything else on shutdown with systemd? (I also looked at, but it's also no good: and I looked in mailing lists too.)

My biggest problem is that the OP of that question wanted to run the script before some mounts were unmounted but I don't have anything like that.

My service is something like this:

Description=Run script before other things stop on shutdown foo.service bar.service foo.service bar.service

ExecStopPost=/bin/sleep 5s


I enable and start this unit after boot, but it doesn't seem to run the script when I shut the instance down. I'm at a loss, how can I do this?

I am using systemd 232 on Debian Stretch.

Related Questions

How to reliably stop services with systemd

Updated November 24, 2017 18:01 PM

"Error(s) encountered" While Using ldapscripts

Updated February 06, 2018 23:01 PM

text render issue ( overwriting )in cinnamon debian

Updated October 24, 2017 12:01 PM