[systemd-devel] Running a service at shutdown time before file systems are unmounted

David Strauss david at davidstrauss.net
Fri Jul 27 19:23:43 PDT 2012


On Fri, Jul 27, 2012 at 6:08 PM, Manuel Amador (Rudd-O)
<rudd-o at rudd-o.com> wrote:
> I need to run a program right before any file system is unmounted, to record
> the current file system state on disk.

I would create a Type=oneshot, RemainAfterExit service with WantedBy=
and After= the mount. You may need to re-"enable" the service or the
mount to get the dependency properly rigged. It's probably possible
for it to have something like "echo" as the ExecStart= and your
utility as the ExecStopPost=. This would cause the service to be
started and "running" when the mount starts up and shut down and run
ExecStopPost before the mount goes away.

I have not tested any of this, but it's the best I can come up with
for allowing clean dependency injection for an arbitrary command to
run before stopping a mount.

-- 
David Strauss
   | david at davidstrauss.net
   | +1 512 577 5827 [mobile]


More information about the systemd-devel mailing list